summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/ttyname.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2006-12-05 21:50:20 +0000
committerJakub Jelinek <jakub@redhat.com>2006-12-05 21:50:20 +0000
commit7f65f3e3920a0dd6bb6a8774f46063371be4d029 (patch)
treefb89eb236014051f866ec94e56070f8120daf00c /sysdeps/unix/sysv/linux/ttyname.c
parent2027fcad9546d0724d9c0994394f2bf69d119613 (diff)
Updated to fedora-glibc-20061205T2141cvs/fedora-glibc-2_5_90-11
Diffstat (limited to 'sysdeps/unix/sysv/linux/ttyname.c')
-rw-r--r--sysdeps/unix/sysv/linux/ttyname.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c
index aed0fd8e0a..1b79787515 100644
--- a/sysdeps/unix/sysv/linux/ttyname.c
+++ b/sysdeps/unix/sysv/linux/ttyname.c
@@ -22,6 +22,7 @@
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
@@ -118,12 +119,12 @@ ttyname (int fd)
int dostat = 0;
char *name;
int save = errno;
+ struct termios term;
- if (__builtin_expect (!__isatty (fd), 0))
- {
- __set_errno (ENOTTY);
- return NULL;
- }
+ /* isatty check, tcgetattr is used because it sets the correct
+ errno (EBADF resp. ENOTTY) on error. */
+ if (__builtin_expect (__tcgetattr (fd, &term) < 0, 0))
+ return NULL;
/* We try using the /proc filesystem. */
*_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0';