toaruos/libc/unistd/ttyname.c
2018-10-09 19:56:45 +09:00

18 lines
278 B
C

#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.h>
static char _tty_name[30]; /* only needs to hold /dev/pty/ttyXXXXXXX */
char * ttyname(int fd) {
if (!isatty(fd)) {
errno = ENOTTY;
return NULL;
}
ioctl(fd, IOCTLTTYNAME, _tty_name);
return _tty_name;
}