diff --git a/src/kernel/libroot/posix/unistd/terminal.c b/src/kernel/libroot/posix/unistd/terminal.c index 08233709ff..53fee1fe19 100644 --- a/src/kernel/libroot/posix/unistd/terminal.c +++ b/src/kernel/libroot/posix/unistd/terminal.c @@ -1,6 +1,6 @@ /* -** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the OpenBeOS License. +** Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the Haiku License. */ @@ -9,39 +9,36 @@ #include #include +#include -/* - * isatty - is the given file descriptor bound to a terminal device? - * - * a simple call to fetch the terminal control attributes suffices - * (only a valid tty device will succeed) - * + +/** isatty - is the given file descriptor bound to a terminal device? + * a simple call to fetch the terminal control attributes suffices + * (only a valid tty device will succeed) */ + int isatty(int fd) { - struct termios term; - - return (tcgetattr(fd, &term) == 0); + struct termios termios; + + return _kern_ioctl(fd, TCGETA, &termios, sizeof(struct termios)) == B_OK; + // we don't use tcgetattr() here in order to keep errno unchanged } -/* - * 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" - * - */ +/** returns the name of the controlling terminal */ + char * ctermid(char *s) { static char defaultBuffer[L_ctermid]; - + char *name = ttyname(1); + // we assume that stdout is our controlling terminal... + if (s == NULL) s = defaultBuffer; - - return strcpy(s, "/dev/tty"); + + return strcpy(s, name ? name : ""); }