From f0d5e1f67bf5d856f7dad926746ca7170560e65f Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 5 Dec 2006 21:28:15 +0000 Subject: * nis/nis_subr.c (nis_getnames): Revert last change. 2006-12-04 Jakub Jelinek * sysdeps/unix/sysv/linux/ttyname.c: Include termios.h. (ttyname): Use tcgetattr instead of isatty, don't set errno to ENOTTY. * sysdeps/unix/sysv/linux/ttyname_r.c: Include termios.h. (__ttyname_r): Use tcgetattr instead of isatty, don't set errno to ENOTTY. * io/Makefile: Add rules to build and run tst-ttyname_r test. * io/tst-ttyname_r.c: New test. --- sysdeps/unix/sysv/linux/ttyname_r.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'sysdeps/unix/sysv/linux/ttyname_r.c') diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c index bd415f1..cef8624 100644 --- a/sysdeps/unix/sysv/linux/ttyname_r.c +++ b/sysdeps/unix/sysv/linux/ttyname_r.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -115,11 +116,11 @@ __ttyname_r (int fd, char *buf, size_t buflen) return ERANGE; } - if (__builtin_expect (!__isatty (fd), 0)) - { - __set_errno (ENOTTY); - return ENOTTY; - } + /* isatty check, tcgetattr is used because it sets the correct + errno (EBADF resp. ENOTTY) on error. */ + struct termios term; + if (__builtin_expect (__tcgetattr (fd, &term) < 0, 0)) + return errno; /* We try using the /proc filesystem. */ *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0'; -- cgit v1.1