Skip to content

Commit cf26e81

Browse files
committed
test: replace libc::isatty with IsTerminal trait
1 parent 594aa1e commit cf26e81

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

misc/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ rust-version.workspace = true
99

1010
[dependencies]
1111
clap.workspace = true
12-
libc.workspace = true
1312
gettext-rs.workspace = true
1413

1514
[dev-dependencies]

misc/test.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@
1111
// - fix and test unary ops
1212
//
1313

14-
use std::os::unix::fs::{FileTypeExt, MetadataExt, PermissionsExt};
15-
use std::path::Path;
14+
use std::{
15+
io::IsTerminal,
16+
os::{
17+
fd::{BorrowedFd, RawFd},
18+
unix::fs::{FileTypeExt, MetadataExt, PermissionsExt},
19+
},
20+
path::Path,
21+
};
1622

1723
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
1824

@@ -132,17 +138,14 @@ fn eval_unary_path(op: &UnaryOp, s: &str) -> bool {
132138
}
133139

134140
fn eval_terminal(s: &str) -> bool {
135-
let fd = match s.parse::<u32>() {
141+
let fd = match s.parse::<RawFd>() {
136142
Ok(f) => f,
137143
Err(_) => {
138144
return false;
139145
}
140146
};
141147

142-
// Normally, posixutils would use the atty crate.
143-
// Passing an arbitrary fd requires unsafe isatty in this case.
144-
145-
unsafe { libc::isatty(fd as i32) == 1 }
148+
unsafe { BorrowedFd::borrow_raw(fd).is_terminal() }
146149
}
147150

148151
fn eval_unary(op_str: &str, s: &str) -> bool {

0 commit comments

Comments
 (0)