about summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/fd_to_filename.h4
-rw-r--r--sysdeps/unix/sysv/linux/fd_to_filename.h34
2 files changed, 15 insertions, 23 deletions
diff --git a/sysdeps/generic/fd_to_filename.h b/sysdeps/generic/fd_to_filename.h
index bacfe5bf52..d41b345a9d 100644
--- a/sysdeps/generic/fd_to_filename.h
+++ b/sysdeps/generic/fd_to_filename.h
@@ -16,10 +16,12 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#define FD_TO_FILENAME_SIZE 0
+
 /* In general there is no generic way to query filename for an open
    file descriptor.  */
 static inline const char *
-fd_to_filename (int fd)
+fd_to_filename (int fd, char *buf)
 {
   return NULL;
 }
diff --git a/sysdeps/unix/sysv/linux/fd_to_filename.h b/sysdeps/unix/sysv/linux/fd_to_filename.h
index 297716b0ae..62bc9916b0 100644
--- a/sysdeps/unix/sysv/linux/fd_to_filename.h
+++ b/sysdeps/unix/sysv/linux/fd_to_filename.h
@@ -16,30 +16,20 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <stdlib.h>
-#include <string.h>
 #include <sys/stat.h>
-#include <_itoa.h>
+
+#define FD_TO_FILENAME_SIZE ((sizeof ("/proc/self/fd/") - 1) \
+			     + (sizeof ("4294967295") - 1) + 1)
 
 static inline const char *
-fd_to_filename (int fd)
+fd_to_filename (unsigned int fd, char *buf)
 {
-  char *ret = malloc (30);
-
-  if (ret != NULL)
-    {
-      struct stat64 st;
-
-      *_fitoa_word (fd, __stpcpy (ret, "/proc/self/fd/"), 10, 0) = '\0';
-
-      /* We must make sure the file exists.  */
-      if (__lxstat64 (_STAT_VER, ret, &st) < 0)
-	{
-	  /* /proc is not mounted or something else happened.  Don't
-	     return the file name.  */
-	  free (ret);
-	  ret = NULL;
-	}
-    }
-  return ret;
+  *_fitoa_word (fd, __stpcpy (buf, "/proc/self/fd/"), 10, 0) = '\0';
+
+  /* We must make sure the file exists.  */
+  struct stat64 st;
+  if (__lxstat64 (_STAT_VER, buf, &st) < 0)
+    /* /proc is not mounted or something else happened.  */
+    return NULL;
+  return buf;
 }