]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* sysdeps/unix/sysv/linux/ttyname.c: Include termios.h.
authorJakub Jelinek <jakub@redhat.com>
Fri, 12 Jan 2007 17:27:52 +0000 (17:27 +0000)
committerJakub Jelinek <jakub@redhat.com>
Fri, 12 Jan 2007 17:27:52 +0000 (17:27 +0000)
(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.

io/Makefile
sysdeps/unix/sysv/linux/ttyname.c
sysdeps/unix/sysv/linux/ttyname_r.c

index c06d747d4af5a9c0d647ffe6b47cad47f9086d06..d4e04d260ab58b96e2014ea0088086f371361237 100644 (file)
@@ -66,7 +66,7 @@ tests         := test-utime test-stat test-stat2 test-lfs tst-getcwd \
                   tst-openat tst-unlinkat tst-fstatat tst-futimesat \
                   tst-renameat tst-fchownat tst-fchmodat tst-faccessat \
                   tst-symlinkat tst-linkat tst-readlinkat tst-mkdirat \
-                  tst-mknodat tst-mkfifoat
+                  tst-mknodat tst-mkfifoat tst-ttyname_r
 
 distribute     := ftwtest-sh
 
index aed0fd8e0a76e53bb9c01caea427c4a063d1b846..1b797875155e1474822af604245f2e02e2f5b319 100644 (file)
@@ -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';
index bd415f167b415f741b74feb3af016627ea97fe43..cef8624dc6920ef6a7babecaf94165591154e2ad 100644 (file)
@@ -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';