isatty() and ctermid() now actually work correctly.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9084 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-09-28 01:51:01 +00:00
parent 91f868aeb7
commit af069b1a47
+14 -17
View File
@@ -1,6 +1,6 @@
/* /*
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved. ** Copyright 2003-2004, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License. ** Distributed under the terms of the Haiku License.
*/ */
@@ -9,39 +9,36 @@
#include <unistd.h> #include <unistd.h>
#include <termios.h> #include <termios.h>
#include <syscalls.h>
/*
* isatty - is the given file descriptor bound to a terminal device? /** isatty - is the given file descriptor bound to a terminal device?
*
* a simple call to fetch the terminal control attributes suffices * a simple call to fetch the terminal control attributes suffices
* (only a valid tty device will succeed) * (only a valid tty device will succeed)
*
*/ */
int int
isatty(int fd) isatty(int fd)
{ {
struct termios term; struct termios termios;
return (tcgetattr(fd, &term) == 0); return _kern_ioctl(fd, TCGETA, &termios, sizeof(struct termios)) == B_OK;
// we don't use tcgetattr() here in order to keep errno unchanged
} }
/* /** returns the name of the controlling terminal */
* ctermid - return the name of the controlling terminal
*
* this is a totally useless function!
* (but kept for historical Posix compatibility)
* yes, it *always* returns "/dev/tty"
*
*/
char * char *
ctermid(char *s) ctermid(char *s)
{ {
static char defaultBuffer[L_ctermid]; static char defaultBuffer[L_ctermid];
char *name = ttyname(1);
// we assume that stdout is our controlling terminal...
if (s == NULL) if (s == NULL)
s = defaultBuffer; s = defaultBuffer;
return strcpy(s, "/dev/tty"); return strcpy(s, name ? name : "");
} }