Skip to content

Commit

Permalink
Use 'libc' directly instead of through rustix (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez authored Jan 22, 2024
1 parent c3b72b5 commit 3bb6d45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]
Expand Down
19 changes: 14 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -75,7 +84,7 @@ impl<Stream: AsFd> 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")]
Expand Down

0 comments on commit 3bb6d45

Please sign in to comment.