summaryrefslogtreecommitdiff
path: root/src/unistd
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2024-08-20 12:34:50 -0400
committerRich Felker <dalias@aerifal.cx>2024-08-20 12:45:38 -0400
commitc94a0c16f08894ce3be6dafb0fe80baa77a6ff2a (patch)
tree380614156d998145f3d83d5daf55619e6a4e6f2e /src/unistd
parentee18e584bfe2c694fdd27bd1251ac5b247f864d5 (diff)
downloadmusl-c94a0c16f08894ce3be6dafb0fe80baa77a6ff2a.tar.gz
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 c84971995b3a6d5118f9357c040572f4c78bcd55 introduced the errno collapsing behavior, but prior to that, errno was not set at all by isatty.
Diffstat (limited to 'src/unistd')
-rw-r--r--src/unistd/isatty.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/unistd/isatty.c b/src/unistd/isatty.c
index 75a9c186..21222eda 100644
--- a/src/unistd/isatty.c
+++ b/src/unistd/isatty.c
@@ -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;
}