Skip to content

Commit e417bd1

Browse files
committed
wc: replace nix by rustix
1 parent 5d7cfab commit e417bd1

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

Cargo.lock

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

fuzz/Cargo.lock

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

src/uu/wc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ unicode-width = { workspace = true }
3333

3434
[target.'cfg(unix)'.dependencies]
3535
libc = { workspace = true }
36-
nix = { workspace = true }
36+
rustix = { workspace = true, features = ["fs"] }
3737

3838
[dev-dependencies]
3939
divan = { workspace = true }

src/uu/wc/src/count_fast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use std::io::{self, ErrorKind, Read};
1616
#[cfg(unix)]
1717
use libc::{_SC_PAGESIZE, S_IFREG, sysconf};
1818
#[cfg(unix)]
19-
use nix::sys::stat;
20-
#[cfg(unix)]
2119
use std::io::{Seek, SeekFrom};
2220
#[cfg(unix)]
2321
use std::os::fd::{AsFd, AsRawFd};
@@ -49,7 +47,9 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
4947
.write(true)
5048
.open("/dev/null")
5149
.map_err(|_| 0_usize)?;
52-
let null_rdev = stat::fstat(null_file.as_fd()).map_err(|_| 0_usize)?.st_rdev as libc::dev_t;
50+
let null_rdev = rustix::fs::fstat(null_file.as_fd())
51+
.map_err(|_| 0_usize)?
52+
.st_rdev as libc::dev_t;
5353
if (libc::major(null_rdev), libc::minor(null_rdev)) != (1, 3) {
5454
// This is not a proper /dev/null, writing to it is probably bad
5555
// Bit of an edge case, but it has been known to happen
@@ -92,7 +92,7 @@ pub(crate) fn count_bytes_fast<T: WordCountable>(handle: &mut T) -> (usize, Opti
9292
#[cfg(unix)]
9393
{
9494
let fd = handle.as_fd();
95-
if let Ok(stat) = stat::fstat(fd) {
95+
if let Ok(stat) = rustix::fs::fstat(fd) {
9696
// If the file is regular, then the `st_size` should hold
9797
// the file's size in bytes.
9898
// If stat.st_size = 0 then

src/uu/wc/src/wc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,10 @@ impl<'a> Input<'a> {
297297

298298
#[cfg(unix)]
299299
fn is_stdin_small_file() -> bool {
300-
use nix::sys::stat;
301300
use std::os::fd::AsFd;
302301

303302
matches!(
304-
stat::fstat(io::stdin().as_fd()),
303+
rustix::fs::fstat(io::stdin().as_fd()),
305304
Ok(meta) if meta.st_mode as libc::mode_t & libc::S_IFMT == libc::S_IFREG && meta.st_size <= (10 << 20)
306305
)
307306
}

0 commit comments

Comments
 (0)