wc: remove a nest by loop{}

This commit is contained in:
oech3
2026-05-28 19:47:04 +09:00
committed by Daniel Hofstetter
parent b22013ab79
commit 55549fa87e

View File

@@ -52,17 +52,13 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
}
}
let (pipe_rd, pipe_wr) = pipe::<false>(MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)?;
loop {
match splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)? {
0 => return Ok(byte_count),
res => {
byte_count += res;
// pipe to null is not blocked. So this returns res at most cases
// next splice does not hang if we discarded 1+ pages
splice(&pipe_rd, &null_file, res).map_err(|_| byte_count)?;
}
}
while let s @ 1.. = splice(fd, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE).map_err(|_| byte_count)? {
byte_count += s;
// pipe to null is not blocked. So this returns the same length at most cases
// next splice does not hang if we discarded 1+ pages
splice(&pipe_rd, &null_file, s).map_err(|_| byte_count)?;
}
Ok(byte_count)
}
/// In the special case where we only need to count the number of bytes. There