X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fopenat-proc.c;h=4a470c5b9d0dc5cf34c18623c9762c6ed7619dfd;hb=8f3cd38b6c08109ec9edea0e7712e9a7a920a2d8;hp=483201ce59a1b019cd11992e41d17f3e9771ae30;hpb=441aa3044f43e5572f58c354f01e6bc070acd5c7;p=gnulib.git diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 483201ce5..4a470c5b9 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c @@ -1,6 +1,6 @@ /* Create /proc/self/fd-related names for subfiles of open directories. - Copyright (C) 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,12 +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, @@ -51,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) { @@ -74,7 +75,7 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) problem is exhibited on code that built on Solaris 8 and running on Solaris 10. */ - int proc_self_fd = open ("/proc/self/fd", O_RDONLY); + int proc_self_fd = open ("/proc/self/fd", O_SEARCH); if (proc_self_fd < 0) proc_status = -1; else @@ -97,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; }