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"); }