about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/ttyname_r.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-10-29 15:17:25 +0000
committerUlrich Drepper <drepper@redhat.com>1998-10-29 15:17:25 +0000
commitc5e340c71ba6f4563ca5fa245baa82b6363ddb2e (patch)
tree3ff655dfee624df411e1f3ebc062181fc0f3f338 /sysdeps/unix/sysv/linux/ttyname_r.c
parent05e951cd1ae7917ce25ec96cc17ebcbf401e345c (diff)
downloadglibc-c5e340c71ba6f4563ca5fa245baa82b6363ddb2e.tar.gz
glibc-c5e340c71ba6f4563ca5fa245baa82b6363ddb2e.tar.xz
glibc-c5e340c71ba6f4563ca5fa245baa82b6363ddb2e.zip
Update.
1998-10-29  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/linux/ttyname_r.c (ttyname_r): Try reading
	/prof/self/fd/FD first.
	* sysdeps/unix/sysv/linux/ttyname.c (ttyname): Likewise.

	* stdio-common/_itoa.h (_fitoa_word): New inline function.  Write
	formatted number starting at given position and return pointer to
	following byte.
	(_fitoa): Likewise, for long long.
Diffstat (limited to 'sysdeps/unix/sysv/linux/ttyname_r.c')
-rw-r--r--sysdeps/unix/sysv/linux/ttyname_r.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c
index 9c859caa25..8306cf56c0 100644
--- a/sysdeps/unix/sysv/linux/ttyname_r.c
+++ b/sysdeps/unix/sysv/linux/ttyname_r.c
@@ -26,6 +26,8 @@
 #include <string.h>
 #include <stdlib.h>
 
+#include <stdio-common/_itoa.h>
+
 static int getttyname_r __P ((int fd, char *buf, size_t buflen,
 			      dev_t mydev, ino_t myino, int save,
 			      int *dostat)) internal_function;
@@ -102,6 +104,7 @@ __ttyname_r (fd, buf, buflen)
      char *buf;
      size_t buflen;
 {
+  char procname[30];
   struct stat st, st1;
   int dostat = 0;
   int save = errno;
@@ -127,6 +130,18 @@ __ttyname_r (fd, buf, buflen)
       return ENOTTY;
     }
 
+  /* We try using the /proc filesystem.  */
+  *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
+
+  ret = __readlink (procname, buf, buflen - 1);
+  if (ret != -1)
+    return 0;
+  if (errno == ENAMETOOLONG)
+    {
+      __set_errno (ERANGE);
+      return ERANGE;
+    }
+
   if (fstat (fd, &st) < 0)
     return errno;