toaruos/libc/unistd/ttyname.c

26 lines
460 B
C
Raw Normal View History

2021-09-18 07:30:47 +03:00
#include <stdint.h>
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
}
2021-09-18 07:30:47 +03:00
int ttyname_r(int fd, char * buf, size_t buflen) {
if (!isatty(fd)) return ENOTTY;
if (buflen < 30) return ERANGE;
ioctl(fd, IOCTLTTYNAME, buf);
return 0;
}