Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/uu/wc/src/count_fast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const FILE_ATTRIBUTE_NORMAL: u32 = 128;
#[cfg(any(target_os = "linux", target_os = "android"))]
use libc::S_IFIFO;
#[cfg(any(target_os = "linux", target_os = "android"))]
use uucore::pipes::{MAX_ROOTLESS_PIPE_SIZE, pipe, splice, splice_exact};
use uucore::pipes::{MAX_ROOTLESS_PIPE_SIZE, pipe, splice};

const BUF_SIZE: usize = 64 * 1024;

Expand Down Expand Up @@ -59,9 +59,12 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
loop {
match splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {
Ok(0) => return Ok(byte_count),
Ok(res) => {
byte_count += res;
splice_exact(&pipe_rd, &null_file, res).map_err(|_| byte_count)?;
Ok(mut discard) => {
byte_count += discard;
while discard > 0 {
// pipe to null is not blocked. So this loop is just once at most cases...
discard -= splice(&pipe_rd, &null_file, discard).map_err(|_| byte_count)?;
}
}
Err(_) => return Err(byte_count),
}
Expand Down
Loading