Skip to content

Commit e0f0318

Browse files
oech3cakebaker
authored andcommitted
tee: reduce if block
1 parent 4816308 commit e0f0318

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/uu/tee/src/tee.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,18 @@ fn copy(mut input: impl Read, mut output: impl Write) -> Result<usize> {
231231
let mut len = 0;
232232

233233
loop {
234-
let received = match input.read(&mut buffer) {
235-
Ok(bytes_count) => bytes_count,
236-
Err(e) if e.kind() == ErrorKind::Interrupted => continue,
234+
match input.read(&mut buffer) {
235+
Ok(0) => return Ok(len), // end of file
236+
Ok(received) => {
237+
output.write_all(&buffer[..received])?;
238+
// flush the buffer to comply with POSIX requirement that
239+
// `tee` does not buffer the input.
240+
output.flush()?;
241+
len += received;
242+
}
243+
Err(e) if e.kind() == ErrorKind::Interrupted => {}
237244
Err(e) => return Err(e),
238-
};
239-
240-
if received == 0 {
241-
return Ok(len);
242245
}
243-
244-
output.write_all(&buffer[0..received])?;
245-
246-
// We need to flush the buffer here to comply with POSIX requirement that
247-
// `tee` does not buffer the input.
248-
output.flush()?;
249-
len += received;
250246
}
251247
}
252248

0 commit comments

Comments
 (0)