This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
ttyname.c
- From: Joel Sherrill <joel dot sherrill at oarcorp dot com>
- To: "newlib at sources dot redhat dot com" <newlib at sources dot redhat dot com>
- Date: Tue, 18 Nov 2008 16:13:12 -0600
- Subject: ttyname.c
Hi,
With RTEMS, we build newlib before the OS. We do not have
access to termios yet. So the new ttyname.c does not compile
for RTEMS inside newlib. Would it be OK to use isatty()
instead of this?
/* Must be a terminal. */
if (tcgetattr (fd, &tty) < 0)
return errno; /* Can be EBADF or ENOTTY */
newlib already assumes isatty() exists.
Attached is a patch.
2008-11-18 Joel Sherrill <joel.sherrill@oarcorp.com>
* libc/unix/ttyname.c: Use isatty() instead of tcgetattr().
--
Joel Sherrill, Ph.D. Director of Research & Development
joel.sherrill@OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
Index: ttyname.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/unix/ttyname.c,v
retrieving revision 1.5
diff -u -r1.5 ttyname.c
--- ttyname.c 18 Nov 2008 21:39:10 -0000 1.5
+++ ttyname.c 18 Nov 2008 22:12:00 -0000
@@ -32,7 +32,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
-#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <paths.h>
@@ -51,15 +50,14 @@
size_t namesize)
{
struct stat sb;
- struct termios tty;
struct dirent *dirp;
DIR *dp;
struct stat dsb;
char buf[sizeof(ttyname_buf)];
/* Must be a terminal. */
- if (tcgetattr (fd, &tty) < 0)
- return errno; /* Can be EBADF or ENOTTY */
+ if (!isatty(fd))
+ return ENOTTY; /* Can be EBADF or ENOTTY */
/* Must be a character device. */
if (fstat (fd, &sb) || !S_ISCHR (sb.st_mode))