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
1 changed files with 19 additions and 22 deletions

View File

@ -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 <unistd.h>
#include <termios.h>
#include <syscalls.h>
/*
* 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 : "");
}