@@ -40,20 +40,18 @@ const BUF_SIZE: usize = 64 * 1024;
4040#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
4141fn count_bytes_using_splice ( fd : & impl AsFd ) -> Result < usize , usize > {
4242 let null_file = uucore:: pipes:: dev_null ( ) . ok_or ( 0_usize ) ?;
43- let mut byte_count = 0 ;
44- if let Ok ( res) = splice ( fd, & null_file, MAX_ROOTLESS_PIPE_SIZE ) {
45- byte_count += res;
43+ if let Ok ( mut byte_count) = splice ( fd, & null_file, MAX_ROOTLESS_PIPE_SIZE ) {
4644 // no need to increase pipe size of input fd since
4745 // - sender with splice probably increased size already
4846 // - sender without splice is bottleneck of our wc -c
4947 loop {
50- match splice ( fd, & null_file, MAX_ROOTLESS_PIPE_SIZE ) {
51- Ok ( 0 ) => return Ok ( byte_count) ,
52- Ok ( res) => byte_count += res,
53- Err ( _) => return Err ( byte_count) ,
48+ match splice ( fd, & null_file, MAX_ROOTLESS_PIPE_SIZE ) . map_err ( |_| byte_count) ? {
49+ 0 => return Ok ( byte_count) ,
50+ res => byte_count += res,
5451 }
5552 }
5653 } else {
54+ let mut byte_count = 0 ;
5755 // input is not pipe. needs broker to use splice() with additional cost
5856 let ( pipe_rd, pipe_wr) = pipe :: < false > ( MAX_ROOTLESS_PIPE_SIZE ) . map_err ( |_| 0_usize ) ?;
5957 loop {
0 commit comments