From b2b584ec5f7b7bf2ea575c7a683450741d0adff3 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 20 Jan 2026 10:55:54 +0000 Subject: [PATCH] uutests: replace unsafe `libc::stat` with `nix::stat` (#10364) No functional change intended. --- tests/uutests/src/lib/util.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index 5c5ed3ef4..0c4bd2553 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -20,6 +20,8 @@ use libc::mode_t; use nix::pty::OpenptyResult; #[cfg(unix)] use nix::sys; +#[cfg(not(windows))] +use nix::sys::stat::{self, SFlag}; use pretty_assertions::assert_eq; #[cfg(unix)] use rlimit::setrlimit; @@ -1144,28 +1146,14 @@ impl AtPath { #[cfg(not(windows))] pub fn is_fifo(&self, fifo: &str) -> bool { - unsafe { - let name = CString::new(self.plus_as_string(fifo)).unwrap(); - let mut stat: libc::stat = std::mem::zeroed(); - if libc::stat(name.as_ptr(), &raw mut stat) >= 0 { - libc::S_IFIFO & stat.st_mode as libc::mode_t != 0 - } else { - false - } - } + stat::stat(&self.plus(fifo)) + .is_ok_and(|s| SFlag::from_bits_truncate(s.st_mode).contains(SFlag::S_IFIFO)) } #[cfg(not(windows))] pub fn is_char_device(&self, char_dev: &str) -> bool { - unsafe { - let name = CString::new(self.plus_as_string(char_dev)).unwrap(); - let mut stat: libc::stat = std::mem::zeroed(); - if libc::stat(name.as_ptr(), &raw mut stat) >= 0 { - libc::S_IFCHR & stat.st_mode as libc::mode_t != 0 - } else { - false - } - } + stat::stat(&self.plus(char_dev)) + .is_ok_and(|s| SFlag::from_bits_truncate(s.st_mode).contains(SFlag::S_IFCHR)) } pub fn hard_link(&self, original: &str, link: &str) {