From 3bb6d45664d86ef2dbffc890d03c7ea42b179bad Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 22 Jan 2024 04:42:04 -0800 Subject: [PATCH] Use 'libc' directly instead of through rustix (#26) --- Cargo.toml | 5 +++-- src/lib.rs | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 840ef16..604478b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,8 +15,8 @@ edition = "2018" include = ["src", "build.rs", "Cargo.toml", "COPYRIGHT", "LICENSE*", "/*.md"] rust-version = "1.63" -[target.'cfg(not(any(windows, target_os = "hermit", target_os = "unknown")))'.dependencies] -rustix = { version = "0.38.0", features = ["termios"] } +[target.'cfg(any(unix, target_os = "wasi"))'.dependencies] +libc = "0.2" [target.'cfg(target_os = "hermit")'.dependencies] hermit-abi = "0.3.0" @@ -33,6 +33,7 @@ features = [ atty = "0.2.14" [target.'cfg(any(unix, target_os = "wasi"))'.dev-dependencies] +rustix = { version = "0.38.0", features = ["termios"] } libc = "0.2.110" [target.'cfg(not(any(windows, target_os = "hermit", target_os = "unknown")))'.dev-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 56810b7..7ef4c75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,10 +25,19 @@ //! //! [`isatty`]: https://man7.org/linux/man-pages/man3/isatty.3.html -#![cfg_attr(unix, no_std)] - -#[cfg(not(any(windows, target_os = "hermit", target_os = "unknown")))] -use rustix::fd::AsFd; +#![cfg_attr( + not(any( + unix, + windows, + target_os = "wasi", + target_os = "hermit", + target_os = "unknown" + )), + no_std +)] + +#[cfg(any(unix, target_os = "wasi"))] +use std::os::fd::{AsFd, AsRawFd}; #[cfg(target_os = "hermit")] use std::os::hermit::io::AsFd; #[cfg(windows)] @@ -75,7 +84,7 @@ impl IsTerminal for Stream { fn is_terminal(&self) -> bool { #[cfg(any(unix, target_os = "wasi"))] { - rustix::termios::isatty(self) + unsafe { libc::isatty(self.as_fd().as_raw_fd()) == 1 } } #[cfg(target_os = "hermit")]