bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* areadlink-with-size: Set errno upon failure
@ 2020-06-27  0:10 Bruno Haible
  0 siblings, 0 replies; only message in thread
From: Bruno Haible @ 2020-06-27  0:10 UTC (permalink / raw)
  To: bug-gnulib

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;
         }
 



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-27  0:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27  0:10 areadlink-with-size: Set errno upon failure Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).