X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Fopenat-proc.c;h=4a470c5b9d0dc5cf34c18623c9762c6ed7619dfd;hb=8f3cd38b6c08109ec9edea0e7712e9a7a920a2d8;hp=51a8aa2cd8b7f586872d09b35f2ce2eeaf97cf7b;hpb=d60f3b0c6b0f93a601acd1cfd3923f94ca05abb0;p=gnulib.git diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 51a8aa2cd..4a470c5b9 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -26,13 +26,12 @@ #include #include +#include #include #include -#include "dirname.h" #include "intprops.h" #include "same-inode.h" -#include "xalloc.h" /* The results of open() in this file are not used with fchdir, and we do not leak fds to any single-threaded code that could use stdio, @@ -52,7 +51,8 @@ /* Set BUF to the expansion of PROC_SELF_FD_FORMAT, using FD and FILE respectively for %d and %s. If successful, return BUF if the result fits in BUF, dynamically allocated memory otherwise. But - return NULL if /proc is not reliable. */ + return NULL if /proc is not reliable, either because the operating + system support is lacking or because memory is low. */ char * openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) { @@ -98,7 +98,13 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) else { size_t bufsize = PROC_SELF_FD_NAME_SIZE_BOUND (strlen (file)); - char *result = (bufsize < OPENAT_BUFFER_SIZE ? buf : xmalloc (bufsize)); + char *result = buf; + if (OPENAT_BUFFER_SIZE < bufsize) + { + result = malloc (bufsize); + if (! result) + return NULL; + } sprintf (result, PROC_SELF_FD_FORMAT, fd, file); return result; }