about summary refs log tree commit diff
path: root/sysdeps/unix/sysv
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-02-18 21:04:15 +0000
committerUlrich Drepper <drepper@redhat.com>2003-02-18 21:04:15 +0000
commit2f7dc59492a588a9b196c13a519fb5f2e42c274d (patch)
treef72fb330f6939009c95b08d23ca26e45b7b68ab1 /sysdeps/unix/sysv
parentba25bb0f1d140994dc0b6ee5f074d1237c493ee5 (diff)
downloadglibc-2f7dc59492a588a9b196c13a519fb5f2e42c274d.tar.gz
glibc-2f7dc59492a588a9b196c13a519fb5f2e42c274d.tar.xz
glibc-2f7dc59492a588a9b196c13a519fb5f2e42c274d.zip
Update.
2003-02-18  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/unix/sysv/linux/ttyname_r.c (__ttyname_r): Recognize
	invalid file descriptors and missing access permissions.
Diffstat (limited to 'sysdeps/unix/sysv')
-rw-r--r--sysdeps/unix/sysv/linux/ttyname_r.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c
index c23ded23c7..924b491e06 100644
--- a/sysdeps/unix/sysv/linux/ttyname_r.c
+++ b/sysdeps/unix/sysv/linux/ttyname_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,92,93,1995-1999,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,1995-2001, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -115,26 +115,35 @@ __ttyname_r (int fd, char *buf, size_t buflen)
       return ERANGE;
     }
 
+  /* 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 && errno == ENOENT)
+    {
+      __set_errno (EBADF);
+      return EBADF;
+    }
+  if (ret == -1 && errno == EACCES)
+    return EACCES;
+
   if (!__isatty (fd))
     {
       __set_errno (ENOTTY);
       return ENOTTY;
     }
 
-  /* We try using the /proc filesystem.  */
-  *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';
+  if (ret == -1 && errno == ENAMETOOLONG)
+    {
+      __set_errno (ERANGE);
+      return ERANGE;
+    }
 
-  ret = __readlink (procname, buf, buflen - 1);
   if (ret != -1 && buf[0] != '[')
     {
       buf[ret] = '\0';
       return 0;
     }
-  if (ret == -1 && errno == ENAMETOOLONG)
-    {
-      __set_errno (ERANGE);
-      return ERANGE;
-    }
 
   if (__fxstat64 (_STAT_VER, fd, &st) < 0)
     return errno;