Skip to content

Commit 02104f3

Browse files
oech3cakebaker
authored andcommitted
tee: remove unused returned usize
1 parent 2d5e77d commit 02104f3

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

src/uu/tee/src/tee.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ fn tee(options: &Options) -> Result<()> {
111111
}
112112

113113
/// Copies all bytes from the input buffer to the output buffer.
114-
///
115-
/// Returns the number of written bytes.
116-
fn copy(mut input: impl Read, mut output: impl Write) -> Result<usize> {
114+
fn copy(mut input: impl Read, mut output: impl Write) -> Result<()> {
117115
// The implementation for this function is adopted from the generic buffer copy implementation from
118116
// the standard library:
119117
// https://github.com/rust-lang/rust/blob/2feb91181882e525e698c4543063f4d0296fcf91/library/std/src/io/copy.rs#L271-L297
@@ -126,38 +124,31 @@ fn copy(mut input: impl Read, mut output: impl Write) -> Result<usize> {
126124
8 * 1024
127125
};
128126
let mut buffer = [0u8; BUF_SIZE];
129-
let mut len = 0;
130127

131-
loop {
128+
for _ in 0..2 {
132129
match input.read(&mut buffer) {
133-
Ok(0) => return Ok(len), // end of file
130+
Ok(0) => return Ok(()), // end of file
134131
Ok(received) => {
135132
output.write_all(&buffer[..received])?;
136133
// flush the buffer to comply with POSIX requirement that
137134
// `tee` does not buffer the input.
138135
output.flush()?;
139-
len += received;
140-
if len > 2 * BUF_SIZE {
141-
// buffer is too small
142-
break;
143-
}
144136
}
145137
Err(e) if e.kind() == ErrorKind::Interrupted => {}
146138
Err(e) => return Err(e),
147139
}
148140
}
149-
// optimize for large input
141+
// buffer is too small optimize for large input
150142
//stack array makes code path for smaller file slower
151143
let mut buffer = vec![0u8; 4 * BUF_SIZE];
152144
loop {
153145
match input.read(&mut buffer) {
154-
Ok(0) => return Ok(len), // end of file
146+
Ok(0) => return Ok(()), // end of file
155147
Ok(received) => {
156148
output.write_all(&buffer[..received])?;
157149
// flush the buffer to comply with POSIX requirement that
158150
// `tee` does not buffer the input.
159151
output.flush()?;
160-
len += received;
161152
}
162153
Err(e) if e.kind() == ErrorKind::Interrupted => {}
163154
Err(e) => return Err(e),

0 commit comments

Comments
 (0)