[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
areadlink-with-size: Set errno upon failure
From: |
Bruno Haible |
Subject: |
areadlink-with-size: Set errno upon failure |
Date: |
Sat, 27 Jun 2020 02:10:44 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; ) |
The areadlink_with_size is documented to set errno when it returns NULL.
To guarantee this also on native Windows, one needs either an explicit
errno = ENOMEM;
assignment, or a dependency to the 'malloc-posix' module.
For consistency with lib/amemxfrm.c, lib/astrxfrm.c, lib/areadlinkat-with-size.c
I'm choosing the assignment. This avoids the dependency.
2020-06-26 Bruno Haible <bruno@clisp.org>
areadlink-with-size: Set errno upon failure.
* lib/areadlink-with-size.c (areadlink_with_size): Set errno when malloc
fails.
* lib/areadlinkat-with-size.c (areadlinkat_with_size): Add comment.
diff --git a/lib/areadlink-with-size.c b/lib/areadlink-with-size.c
index d177009..86ddd60 100644
--- a/lib/areadlink-with-size.c
+++ b/lib/areadlink-with-size.c
@@ -79,7 +79,10 @@ areadlink_with_size (char const *file, size_t size)
{
buf = buffer = malloc (buf_size);
if (!buffer)
- return NULL;
+ {
+ errno = ENOMEM;
+ return NULL;
+ }
}
r = readlink (file, buf, buf_size);
diff --git a/lib/areadlinkat-with-size.c b/lib/areadlinkat-with-size.c
index 142b9dc..b41a5e0 100644
--- a/lib/areadlinkat-with-size.c
+++ b/lib/areadlinkat-with-size.c
@@ -84,6 +84,8 @@ areadlinkat_with_size (int fd, char const *file, size_t size)
{
buf = buffer = malloc (buf_size);
if (!buffer)
+ /* We can assume errno == ENOMEM here, since all platforms that
have
+ readlinkat() have a POSIX compliant malloc(). */
return NULL;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- areadlink-with-size: Set errno upon failure,
Bruno Haible <=