@@ -576,6 +576,7 @@ fn unbounded_tail<T: Read>(reader: &mut BufReader<T>, settings: &Settings) -> UR
576576}
577577
578578// Print the target section of the file
579+ // use zero-copy on Linux
579580fn print_target_section <
580581 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ] R : Read + rustix:: fd:: AsFd ,
581582 #[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ] R : Read + ?Sized ,
@@ -586,10 +587,14 @@ fn print_target_section<
586587 let stdout = stdout ( ) ;
587588 let mut stdout = stdout. lock ( ) ;
588589 if let Some ( limit) = limit {
589- let mut reader = file. take ( limit) ;
590- io:: copy ( & mut reader, & mut stdout) ?;
590+ #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
591+ uucore:: pipes:: send_n_bytes ( file, & mut stdout, limit) ?;
592+ #[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
593+ {
594+ let mut reader = file. take ( limit) ;
595+ io:: copy ( & mut reader, & mut stdout) ?;
596+ }
591597 } else {
592- // zero-copy fast-path
593598 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
594599 if uucore:: pipes:: splice_unbounded_broker ( file, & mut stdout) ? {
595600 io:: copy ( file, & mut stdout) ?;
0 commit comments