wc: Fix fallback when pipe() or splice() failed

This commit is contained in:
oech3
2026-04-25 16:52:37 +02:00
committed by Daniel Hofstetter
parent e348e13e77
commit 020124b5a6
+3 -5
View File
@@ -48,7 +48,7 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
// - sender without splice is bottleneck of our wc -c
loop {
match splice(fd, &null_file, MAX_ROOTLESS_PIPE_SIZE) {
Ok(0) => break,
Ok(0) => return Ok(byte_count),
Ok(res) => byte_count += res,
Err(_) => return Err(byte_count),
}
@@ -57,7 +57,7 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
// input is not pipe. needs broker to use splice() with additional cost
loop {
match splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) {
Ok(0) => break,
Ok(0) => return Ok(byte_count),
Ok(res) => {
byte_count += res;
splice_exact(&pipe_rd, &null_file, res).map_err(|_| byte_count)?;
@@ -66,10 +66,8 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
}
}
} else {
return Ok(0_usize);
Err(0)
}
Ok(byte_count)
}
/// In the special case where we only need to count the number of bytes. There