mirror of https://git.musl-libc.org/git/musl
Browse Source
POSIX allows ttyname(_r) and isatty to return EBADF if passed file
descriptor is invalid.
maintainer's note: these are optional ("may fail") errors, but it's
non-conforming for ttyname_r to return ENOTTY when it failed for a
different reason.
master
committed by
Rich Felker
2 changed files with 6 additions and 2 deletions
@ -1,9 +1,13 @@ |
|||||
#include <unistd.h> |
#include <unistd.h> |
||||
|
#include <errno.h> |
||||
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
||||
#include "syscall.h" |
#include "syscall.h" |
||||
|
|
||||
int isatty(int fd) |
int isatty(int fd) |
||||
{ |
{ |
||||
struct winsize wsz; |
struct winsize wsz; |
||||
return !__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz); |
unsigned long r = syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz); |
||||
|
if (r == 0) return 1; |
||||
|
if (errno != EBADF) errno = ENOTTY; |
||||
|
return 0; |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue