Skip to content

Commit a26f0a7

Browse files
committed
refactor(sort): replace unsafe libc::fcntl with rustix::io::fcntl_getfd
1 parent a04e491 commit a26f0a7

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/uu/sort/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ foldhash = { workspace = true }
5151
ctrlc = { workspace = true }
5252

5353
[target.'cfg(unix)'.dependencies]
54-
nix = { workspace = true, features = ["resource"] }
54+
libc = { workspace = true }
55+
rustix = { workspace = true, features = ["process", "param", "fs"] }
5556

5657
[dev-dependencies]
5758
divan = { workspace = true }

src/uu/sort/src/sort.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,9 +1436,10 @@ pub(crate) fn current_open_fd_count() -> Option<usize> {
14361436

14371437
let mut count = 0usize;
14381438
for fd in 0..limit {
1439-
let fd = fd as libc::c_int;
1440-
// Probe with libc::fcntl because the fd may be invalid.
1441-
if unsafe { libc::fcntl(fd, libc::F_GETFD) } != -1 {
1439+
let fd = fd as std::os::fd::RawFd;
1440+
// SAFETY: We are only probing whether the fd is valid via fcntl_getfd;
1441+
// the borrowed fd is not used beyond this call.
1442+
if rustix::io::fcntl_getfd(unsafe { std::os::fd::BorrowedFd::borrow_raw(fd) }).is_ok() {
14421443
count = count.saturating_add(1);
14431444
}
14441445
}

0 commit comments

Comments
 (0)