aboutsummaryrefslogtreecommitdiffstats
path: root/sysdeps/unix/sysv/linux/fd_to_filename.h
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv/linux/fd_to_filename.h')
-rw-r--r--sysdeps/unix/sysv/linux/fd_to_filename.h34
1 files changed, 12 insertions, 22 deletions
diff --git a/sysdeps/unix/sysv/linux/fd_to_filename.h b/sysdeps/unix/sysv/linux/fd_to_filename.h
index 297716b0ae3..62bc9916b0f 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;
}