Skip to content

Commit 8dafe57

Browse files
authored
Make the implementation match std. (#33)
Use `!= 0` instead of `== 1` for testing `isatty`'s return value, so that this code follows std as closely as possible. And update the comments in the Windows implementation to reflect that this code matches what's in current std as well.
1 parent 3bb6d45 commit 8dafe57

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/lib.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ impl<Stream: AsFd> IsTerminal for Stream {
8484
fn is_terminal(&self) -> bool {
8585
#[cfg(any(unix, target_os = "wasi"))]
8686
{
87-
unsafe { libc::isatty(self.as_fd().as_raw_fd()) == 1 }
87+
let fd = self.as_fd();
88+
unsafe { libc::isatty(fd.as_raw_fd()) != 0 }
8889
}
8990

9091
#[cfg(target_os = "hermit")]
@@ -104,8 +105,8 @@ impl<Stream: AsHandle> IsTerminal for Stream {
104105
}
105106

106107
// The Windows implementation here is copied from `handle_is_console` in
107-
// std/src/sys/windows/io.rs in Rust at revision
108-
// d7b0bcb20f2f7d5f3ea3489d56ece630147e98f5.
108+
// library/std/src/sys/pal/windows/io.rs in Rust at revision
109+
// 99128b7e45f8b95d962da2e6ea584767f0c85455.
109110

110111
#[cfg(windows)]
111112
fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
@@ -147,8 +148,6 @@ fn handle_is_console(handle: BorrowedHandle<'_>) -> bool {
147148
}
148149

149150
/// Returns true if there is an MSYS tty on the given handle.
150-
///
151-
/// This incoproates d7b0bcb20f2f7d5f3ea3489d56ece630147e98f5
152151
#[cfg(windows)]
153152
unsafe fn msys_tty_on(handle: HANDLE) -> bool {
154153
use std::ffi::c_void;

0 commit comments

Comments
 (0)