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 <[email protected]> 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; }
