Skip to content

Commit 8e63c1b

Browse files
committed
cat: use std::io::copy
1 parent e95946e commit 8e63c1b

1 file changed

Lines changed: 3 additions & 34 deletions

File tree

src/uu/cat/src/cat.rs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,11 @@ fn cat_handle<R: FdReadable>(
363363
state: &mut OutputState,
364364
) -> CatResult<()> {
365365
if options.can_print_fast() {
366-
print_fast(handle)
366+
io::copy(&mut handle.reader, &mut *uucore::stdio::stdout_raw())?;
367367
} else {
368-
print_lines(handle, options, state)
368+
print_lines(handle, options, state)?;
369369
}
370+
Ok(())
370371
}
371372

372373
fn cat_path(path: &OsString, options: &OutputOptions, state: &mut OutputState) -> CatResult<()> {
@@ -477,38 +478,6 @@ fn get_input_type(path: &OsString) -> CatResult<InputType> {
477478
}
478479
}
479480

480-
/// Writes handle to stdout with no configuration. This allows a
481-
/// simple memory copy.
482-
fn print_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
483-
#[cfg(any(target_os = "linux", target_os = "android"))]
484-
{
485-
// If we're on Linux or Android, try to use the splice() system call
486-
// for faster writing. If it works, we're done.
487-
if !splice::write_fast_using_splice(handle, &mut io::stdout())? {
488-
return Ok(());
489-
}
490-
}
491-
// If we're not on Linux or Android, or the splice() call failed,
492-
// fall back on slower writing.
493-
print_unbuffered(handle)
494-
}
495-
496-
#[cfg_attr(any(target_os = "linux", target_os = "android"), inline(never))] // splice fast-path does not require this allocation
497-
fn print_unbuffered<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
498-
let mut stdout = uucore::stdio::stdout_raw();
499-
let mut buf = [0; 1024 * 64];
500-
loop {
501-
match handle.reader.read(&mut buf) {
502-
Ok(0) => return Ok(()),
503-
Ok(n) => stdout
504-
.write_all(&buf[..n])
505-
.inspect_err(handle_broken_pipe)?,
506-
Err(e) if e.kind() != ErrorKind::Interrupted => return Err(e.into()),
507-
_ => {}
508-
}
509-
}
510-
}
511-
512481
/// Outputs file contents to stdout in a line-by-line fashion,
513482
/// propagating any errors that might occur.
514483
fn print_lines<R: FdReadable>(

0 commit comments

Comments
 (0)