toaruos/libc/unistd/ttyname.c

18 lines
278 B
C
Raw Normal View History

2018-06-25 10:28:13 +03:00
#include <unistd.h>
#include <errno.h>
2018-10-09 13:56:45 +03:00
#include <sys/ioctl.h>
static char _tty_name[30]; /* only needs to hold /dev/pty/ttyXXXXXXX */
2018-06-25 10:28:13 +03:00
char * ttyname(int fd) {
2018-10-09 13:56:45 +03:00
if (!isatty(fd)) {
errno = ENOTTY;
return NULL;
}
ioctl(fd, IOCTLTTYNAME, _tty_name);
return _tty_name;
2018-06-25 10:28:13 +03:00
}