]> Savannah Git Hosting - gnulib.git/commitdiff
areadlink-with-size: Set errno upon failure.
authorBruno Haible <bruno@clisp.org>
Sat, 27 Jun 2020 00:06:54 +0000 (02:06 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 27 Jun 2020 00:06:54 +0000 (02:06 +0200)
* lib/areadlink-with-size.c (areadlink_with_size): Set errno when malloc
fails.
* lib/areadlinkat-with-size.c (areadlinkat_with_size): Add comment.

ChangeLog
lib/areadlink-with-size.c
lib/areadlinkat-with-size.c

index a63a00bcf0684a5828596d6c1650c52b57fa86fe..7372a6b37d76a96103cc05eb900ef78c05a113b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+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.
+
 2020-06-26  Bruno Haible  <bruno@clisp.org>
 
        copy-file: Shrink dependencies.
index d1770091de18aea830c64a8d1fb11e9fd06a5608..86ddd6089cd33cf30ee82a5b4e2d6857539f52bc 100644 (file)
@@ -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);
index 142b9dc542b345053e0a7eace0cb533071d5dc06..b41a5e0c4b9ed35e23cce67d1a92ce73d92eabc9 100644 (file)
@@ -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;
         }