@@ -497,31 +497,13 @@ fn print_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
497497}
498498
499499#[ cfg_attr( any( target_os = "linux" , target_os = "android" ) , inline( never) ) ] // splice fast-path does not require this allocation
500- #[ cfg( any( unix, target_os = "wasi" ) ) ]
501- fn print_unbuffered < R : FdReadable > (
502- handle : & mut InputHandle < R > ,
503- stdout : io:: Stdout ,
504- ) -> CatResult < ( ) > {
505- // todo: since there is no cost by 0-fill, we could use larger heap buffer for throughput
506- let mut buf = [ std:: mem:: MaybeUninit :: < u8 > :: uninit ( ) ; 1024 * 64 ] ;
507- // use raw syscall to remove buffering
508- loop {
509- match rustix:: io:: read ( & handle. reader , & mut buf) {
510- Ok ( ( [ ] , _) ) => return Ok ( ( ) ) ,
511- Ok ( ( filled, _) ) => {
512- uucore:: io:: write_all_raw ( & stdout, filled) . inspect_err ( handle_broken_pipe) ?;
513- }
514- Err ( e) if e. kind ( ) != ErrorKind :: Interrupted => return Err ( e. into ( ) ) ,
515- _ => { }
516- }
517- }
518- }
519-
520- #[ cfg( not( any( unix, target_os = "wasi" ) ) ) ]
521500fn print_unbuffered < R : FdReadable > (
522501 handle : & mut InputHandle < R > ,
523502 stdout : io:: Stdout ,
524503) -> CatResult < ( ) > {
504+ #[ cfg( any( unix, target_os = "wasi" ) ) ]
505+ let mut stdout = uucore:: io:: RawWriter ( stdout) ; // use raw syscall to remove buffering
506+ #[ cfg( not( any( unix, target_os = "wasi" ) ) ) ]
525507 let mut stdout = stdout. lock ( ) ;
526508 let mut buf = [ 0 ; 1024 * 64 ] ;
527509 loop {
@@ -531,8 +513,9 @@ fn print_unbuffered<R: FdReadable>(
531513 stdout
532514 . write_all ( & buf[ ..n] )
533515 . inspect_err ( handle_broken_pipe) ?;
534- // we cannot use rustix::io on Windows
516+ // cannot use rustix::io on Windows
535517 // really bad workaround for unbuffered write <https://github.com/uutils/coreutils/issues/12188>
518+ #[ cfg( not( any( unix, target_os = "wasi" ) ) ) ]
536519 stdout. flush ( ) . inspect_err ( handle_broken_pipe) ?;
537520 }
538521 Err ( e) if e. kind ( ) != ErrorKind :: Interrupted => return Err ( e. into ( ) ) ,
0 commit comments