From 59ebc2a7df73266928ac118c7dd495cc064fe8d2 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 12 Apr 2026 17:47:47 +0900 Subject: [PATCH] uucore: replace nix of buf_copy by rustix --- src/uucore/src/lib/features/buf_copy/linux.rs | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/uucore/src/lib/features/buf_copy/linux.rs b/src/uucore/src/lib/features/buf_copy/linux.rs index 7760d668025..1048def2a64 100644 --- a/src/uucore/src/lib/features/buf_copy/linux.rs +++ b/src/uucore/src/lib/features/buf_copy/linux.rs @@ -31,10 +31,10 @@ impl FdWritable for T where T: Write + AsFd + AsRawFd {} const SPLICE_SIZE: usize = 1024 * 128; const BUF_SIZE: usize = 1024 * 16; -/// Conversion from a `nix::Error` into our `Error` which implements `UError`. -impl From for Error { - fn from(error: nix::Error) -> Self { - Self::Io(std::io::Error::from_raw_os_error(error as i32)) +/// Conversion from a `rustix::io::Errno` into our `Error` which implements `UError`. +impl From for Error { + fn from(error: rustix::io::Errno) -> Self { + Self::Io(std::io::Error::from(error)) } } @@ -126,19 +126,19 @@ pub(crate) fn copy_exact( write_fd: &impl AsFd, num_bytes: usize, ) -> std::io::Result { - use nix::unistd; - let mut left = num_bytes; let mut buf = [0; BUF_SIZE]; - let mut written = 0; + let mut total_written = 0; while left > 0 { - let read = unistd::read(read_fd, &mut buf)?; - assert_ne!(read, 0, "unexpected end of pipe"); - while written < read { - let n = unistd::write(write_fd, &buf[written..read])?; + let n_read = rustix::io::read(read_fd, &mut buf)?; + assert_ne!(n_read, 0, "unexpected end of pipe"); + let mut written = 0; + while written < n_read { + let n = rustix::io::write(write_fd, &buf[written..n_read])?; written += n; } - left -= read; + total_written += written; + left -= n_read; } - Ok(written) + Ok(total_written) }