From 953aa0fc95902ac94e089bfe60572901b84e93d4 Mon Sep 17 00:00:00 2001 From: Daniel Reinhold Date: Sun, 4 May 2003 00:53:22 +0000 Subject: [PATCH] fleshed out some tty stuff... isatty() is fixed - altho this is basically academic since we don't have any drivers for terminal devices written yet (but at least the code is ready when we do) also, ctermid() is implemented - which is of no big consequence git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3170 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/posix/unistd/terminal.c | 38 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/kernel/libroot/posix/unistd/terminal.c b/src/kernel/libroot/posix/unistd/terminal.c index a8085e68b0..08233709ff 100644 --- a/src/kernel/libroot/posix/unistd/terminal.c +++ b/src/kernel/libroot/posix/unistd/terminal.c @@ -4,14 +4,44 @@ */ -#include #include +#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) + * + */ int -isatty(int file) +isatty(int fd) { - // ToDo: please fix me! - return file < 3; + struct termios term; + + return (tcgetattr(fd, &term) == 0); +} + + +/* + * 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 * +ctermid(char *s) +{ + static char defaultBuffer[L_ctermid]; + + if (s == NULL) + s = defaultBuffer; + + return strcpy(s, "/dev/tty"); }