summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-01-12 17:27:52 +0000
committerJakub Jelinek <jakub@redhat.com>2007-01-12 17:27:52 +0000
commit6d122c1de8aac283440d1067990beeae7e2679e9 (patch)
treee923bcd20cf24e12476f0db9eb2b3d5e4390e5f4 /sysdeps/unix/sysv/linux
parente8522612818683704ec1792f0837329c0e6455ff (diff)
downloadglibc-6d122c1de8aac283440d1067990beeae7e2679e9.tar
glibc-6d122c1de8aac283440d1067990beeae7e2679e9.tar.gz
glibc-6d122c1de8aac283440d1067990beeae7e2679e9.tar.bz2
glibc-6d122c1de8aac283440d1067990beeae7e2679e9.zip
* 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.
Diffstat (limited to 'sysdeps/unix/sysv/linux')
-rw-r--r--sysdeps/unix/sysv/linux/ttyname.c11
-rw-r--r--sysdeps/unix/sysv/linux/ttyname_r.c11
2 files changed, 12 insertions, 10 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';
diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c
index bd415f167b..cef8624dc6 100644
--- a/sysdeps/unix/sysv/linux/ttyname_r.c
+++ b/sysdeps/unix/sysv/linux/ttyname_r.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>
@@ -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';