Skip to content

Commit f936e22

Browse files
committed
uucore: replace nix of buf_copy by rustix
1 parent b6e4c45 commit f936e22

File tree

1 file changed

+13
-13
lines changed
  • src/uucore/src/lib/features/buf_copy

1 file changed

+13
-13
lines changed

src/uucore/src/lib/features/buf_copy/linux.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ impl<T> FdWritable for T where T: Write + AsFd + AsRawFd {}
3131
const SPLICE_SIZE: usize = 1024 * 128;
3232
const BUF_SIZE: usize = 1024 * 16;
3333

34-
/// Conversion from a `nix::Error` into our `Error` which implements `UError`.
35-
impl From<nix::Error> for Error {
36-
fn from(error: nix::Error) -> Self {
37-
Self::Io(std::io::Error::from_raw_os_error(error as i32))
34+
/// Conversion from a `rustix::io::Errno` into our `Error` which implements `UError`.
35+
impl From<rustix::io::Errno> for Error {
36+
fn from(error: rustix::io::Errno) -> Self {
37+
Self::Io(std::io::Error::from(error))
3838
}
3939
}
4040

@@ -126,19 +126,19 @@ pub(crate) fn copy_exact(
126126
write_fd: &impl AsFd,
127127
num_bytes: usize,
128128
) -> std::io::Result<usize> {
129-
use nix::unistd;
130-
131129
let mut left = num_bytes;
132130
let mut buf = [0; BUF_SIZE];
133-
let mut written = 0;
131+
let mut total_written = 0;
134132
while left > 0 {
135-
let read = unistd::read(read_fd, &mut buf)?;
136-
assert_ne!(read, 0, "unexpected end of pipe");
137-
while written < read {
138-
let n = unistd::write(write_fd, &buf[written..read])?;
133+
let n_read = rustix::io::read(read_fd, &mut buf)?;
134+
assert_ne!(n_read, 0, "unexpected end of pipe");
135+
let mut written = 0;
136+
while written < n_read {
137+
let n = rustix::io::write(write_fd, &buf[written..n_read])?;
139138
written += n;
140139
}
141-
left -= read;
140+
total_written += written;
141+
left -= n_read;
142142
}
143-
Ok(written)
143+
Ok(total_written)
144144
}

0 commit comments

Comments
 (0)