From 2404d0c7a13181d14e7c92824bb7d0e94b5f0f25 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 1 Apr 2026 13:00:47 +0900 Subject: [PATCH] wc: replace nix by rustix --- Cargo.lock | 2 +- fuzz/Cargo.lock | 2 +- src/uu/wc/Cargo.toml | 2 +- src/uu/wc/src/count_fast.rs | 8 ++++---- src/uu/wc/src/wc.rs | 3 +-- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index adf882f2232..0a871f94332 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4433,7 +4433,7 @@ dependencies = [ "codspeed-divan-compat", "fluent", "libc", - "nix", + "rustix", "tempfile", "thiserror 2.0.18", "unicode-width 0.2.2", diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index bd3186e0b18..da97b02dc8d 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -2102,7 +2102,7 @@ dependencies = [ "clap", "fluent", "libc", - "nix", + "rustix", "thiserror", "unicode-width", "uucore", diff --git a/src/uu/wc/Cargo.toml b/src/uu/wc/Cargo.toml index b4c2005af2b..a285d58c8a9 100644 --- a/src/uu/wc/Cargo.toml +++ b/src/uu/wc/Cargo.toml @@ -33,7 +33,7 @@ unicode-width = { workspace = true } [target.'cfg(unix)'.dependencies] libc = { workspace = true } -nix = { workspace = true } +rustix = { workspace = true, features = ["fs"] } [dev-dependencies] divan = { workspace = true } diff --git a/src/uu/wc/src/count_fast.rs b/src/uu/wc/src/count_fast.rs index 5e2ecd080a0..9fe6f8145bc 100644 --- a/src/uu/wc/src/count_fast.rs +++ b/src/uu/wc/src/count_fast.rs @@ -16,8 +16,6 @@ use std::io::{self, ErrorKind, Read}; #[cfg(unix)] use libc::{_SC_PAGESIZE, S_IFREG, sysconf}; #[cfg(unix)] -use nix::sys::stat; -#[cfg(unix)] use std::io::{Seek, SeekFrom}; #[cfg(unix)] use std::os::fd::{AsFd, AsRawFd}; @@ -49,7 +47,9 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result { .write(true) .open("/dev/null") .map_err(|_| 0_usize)?; - let null_rdev = stat::fstat(null_file.as_fd()).map_err(|_| 0_usize)?.st_rdev as libc::dev_t; + let null_rdev = rustix::fs::fstat(null_file.as_fd()) + .map_err(|_| 0_usize)? + .st_rdev as libc::dev_t; if (libc::major(null_rdev), libc::minor(null_rdev)) != (1, 3) { // This is not a proper /dev/null, writing to it is probably bad // Bit of an edge case, but it has been known to happen @@ -92,7 +92,7 @@ pub(crate) fn count_bytes_fast(handle: &mut T) -> (usize, Opti #[cfg(unix)] { let fd = handle.as_fd(); - if let Ok(stat) = stat::fstat(fd) { + if let Ok(stat) = rustix::fs::fstat(fd) { // If the file is regular, then the `st_size` should hold // the file's size in bytes. // If stat.st_size = 0 then diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index eaabbce8c28..5cc1bcd9017 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -297,11 +297,10 @@ impl<'a> Input<'a> { #[cfg(unix)] fn is_stdin_small_file() -> bool { - use nix::sys::stat; use std::os::fd::AsFd; matches!( - stat::fstat(io::stdin().as_fd()), + rustix::fs::fstat(io::stdin().as_fd()), Ok(meta) if meta.st_mode as libc::mode_t & libc::S_IFMT == libc::S_IFREG && meta.st_size <= (10 << 20) ) }