diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-02-18 21:04:15 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-02-18 21:04:15 +0000 |
commit | 2f7dc59492a588a9b196c13a519fb5f2e42c274d (patch) | |
tree | f72fb330f6939009c95b08d23ca26e45b7b68ab1 /sysdeps | |
parent | ba25bb0f1d140994dc0b6ee5f074d1237c493ee5 (diff) | |
download | glibc-2f7dc59492a588a9b196c13a519fb5f2e42c274d.zip glibc-2f7dc59492a588a9b196c13a519fb5f2e42c274d.tar.gz glibc-2f7dc59492a588a9b196c13a519fb5f2e42c274d.tar.bz2 |
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')
-rw-r--r-- | sysdeps/unix/sysv/linux/ttyname_r.c | 27 |
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 c23ded2..924b491 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; |