mirror of
git://git.musl-libc.org/musl
synced 2025-03-02 09:40:24 +00:00
isatty: don't collapse all non-EBADF errors to ENOTTY
linux puts hung-up ttys in a state where ioctls produce EIO, and may
do the same for other types of devices in error or shutdown states.
such an error clearly does not mean the device is not a tty, but it
also can't reliably establish that the device is a tty, so the only
safe thing to do seems to be reporting the error. programs that don't
check errno will conclude that the device is not a tty, which is no
different from what happens now, but at least they gain the option to
differentiate between the cases.
commit c84971995b
introduced the errno
collapsing behavior, but prior to that, errno was not set at all by
isatty.
This commit is contained in:
parent
ee18e584bf
commit
c94a0c16f0
@ -6,8 +6,6 @@
|
||||
int isatty(int fd)
|
||||
{
|
||||
struct winsize wsz;
|
||||
unsigned long r = syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz);
|
||||
if (r == 0) return 1;
|
||||
if (errno != EBADF) errno = ENOTTY;
|
||||
return 0;
|
||||
/* +1 converts from error status (0/-1) to boolean (1/0) */
|
||||
return syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz) + 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user