[Glibc-bsd-commits] r3259 - trunk/glibc-ports/kfreebsd

Aurelien Jarno aurel32 at alioth.debian.org
Tue Feb 8 20:44:08 UTC 2011


Author: aurel32
Date: 2011-02-08 20:44:07 +0000 (Tue, 08 Feb 2011)
New Revision: 3259

Modified:
   trunk/glibc-ports/kfreebsd/ttyname.c
   trunk/glibc-ports/kfreebsd/ttyname_r.c
Log:
Fix tst-ttyname_r.out


Modified: trunk/glibc-ports/kfreebsd/ttyname.c
===================================================================
--- trunk/glibc-ports/kfreebsd/ttyname.c	2011-02-08 18:42:17 UTC (rev 3258)
+++ trunk/glibc-ports/kfreebsd/ttyname.c	2011-02-08 20:44:07 UTC (rev 3259)
@@ -19,6 +19,7 @@
 #include <stddef.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#include <termios.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -37,7 +38,10 @@
   static size_t buflen;
   struct fiodgname_arg fgn;
 
-  if (!__isatty (fd))
+  /* 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 NULL;
 
   if (buflen == 0)

Modified: trunk/glibc-ports/kfreebsd/ttyname_r.c
===================================================================
--- trunk/glibc-ports/kfreebsd/ttyname_r.c	2011-02-08 18:42:17 UTC (rev 3258)
+++ trunk/glibc-ports/kfreebsd/ttyname_r.c	2011-02-08 20:44:07 UTC (rev 3259)
@@ -20,6 +20,7 @@
 #include <stddef.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#include <termios.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
@@ -51,11 +52,11 @@
       return ERANGE;
     }
 
-  if (!__isatty (fd))
-    {
-      __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;
 
   /* Prepare the result buffer.  */
   memcpy (buf, dev, sizeof (dev) - 1);




More information about the Glibc-bsd-commits mailing list