Skip to content

Commit ce30bd9

Browse files
authored
Don't check the errno value from isatty. (#468)
We don't actually do anything different for different errno values, other than panic on unknown ones, and that isn't that isn't adding much value compared to the cost of being an extra surprise when porting to new OS's. Fixes #467.
1 parent 1c81957 commit ce30bd9

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/backend/libc/termios/syscalls.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ use crate::fd::BorrowedFd;
1010
#[cfg(feature = "procfs")]
1111
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
1212
use crate::ffi::CStr;
13+
#[cfg(not(target_os = "wasi"))]
1314
use crate::io;
1415
#[cfg(not(target_os = "wasi"))]
1516
use crate::process::{Pid, RawNonZeroPid};
1617
#[cfg(not(target_os = "wasi"))]
1718
use crate::termios::{Action, OptionalActions, QueueSelector, Speed, Termios, Winsize};
1819
use core::mem::MaybeUninit;
19-
use libc_errno::errno;
2020

2121
#[cfg(not(target_os = "wasi"))]
2222
pub(crate) fn tcgetattr(fd: BorrowedFd<'_>) -> io::Result<Termios> {
@@ -142,26 +142,12 @@ pub(crate) fn cfsetspeed(termios: &mut Termios, speed: Speed) -> io::Result<()>
142142
}
143143

144144
pub(crate) fn isatty(fd: BorrowedFd<'_>) -> bool {
145-
let res = unsafe { c::isatty(borrowed_fd(fd)) };
146-
if res == 0 {
147-
match errno().0 {
148-
#[cfg(not(any(target_os = "android", target_os = "linux")))]
149-
c::ENOTTY => false,
150-
151-
// Old Linux versions reportedly return `EINVAL`.
152-
// <https://man7.org/linux/man-pages/man3/isatty.3.html#ERRORS>
153-
#[cfg(any(target_os = "android", target_os = "linux"))]
154-
c::ENOTTY | c::EINVAL => false,
155-
156-
// Darwin mysteriously returns `EOPNOTSUPP` sometimes.
157-
#[cfg(any(target_os = "ios", target_os = "macos"))]
158-
c::EOPNOTSUPP => false,
159-
160-
err => panic!("unexpected error from isatty: {:?}", err),
161-
}
162-
} else {
163-
true
164-
}
145+
// Use the return value of `isatty` alone. We don't check `errno` because
146+
// we return `bool` rather than `io::Result<bool>`, because we assume
147+
// `BorrrowedFd` protects us from `EBADF`, and any other reasonably
148+
// anticipated errno value would end up interpreted as "assume it's not a
149+
// terminal" anyway.
150+
unsafe { c::isatty(borrowed_fd(fd)) != 0 }
165151
}
166152

167153
#[cfg(feature = "procfs")]

0 commit comments

Comments
 (0)