yac
/
coreutils
Archived
2
0
Fork 0

cat(1): fixed pseudo-unbuffered output

This commit is contained in:
Emma Tebibyte 2022-12-12 18:55:15 -05:00
parent c5123b9d19
commit 3e555542b6
1 changed files with 4 additions and 6 deletions

View File

@ -53,11 +53,7 @@ fn main() -> ExitCode {
if path == "-" { if path == "-" {
loop { loop {
match io::stdin().lock().read_line(&mut output) { match io::stdin().lock().read_line(&mut output) {
Ok(EOF) => { Ok(EOF) => if EOF == 0 { break },
print!("{}", output);
output.clear();
if EOF == 0 { break }
},
Err(_) => { Err(_) => {
eprintln!("Usage: {} [options...] [files...]", &argv0); eprintln!("Usage: {} [options...] [files...]", &argv0);
return ExitCode::Usage; return ExitCode::Usage;
@ -66,13 +62,15 @@ fn main() -> ExitCode {
} }
} else { } else {
match read_to_string(&path) { match read_to_string(&path) {
Ok(output) => print!("{}", output), Ok(output) => {},
Err(_) => { Err(_) => {
eprintln!("{}: {}: No such file or directory.", &argv0, &path); eprintln!("{}: {}: No such file or directory.", &argv0, &path);
return ExitCode::NoInput; return ExitCode::NoInput;
}, },
}; };
} }
print!("{}", output);
output.clear();
} }
match io::stdout().flush() { match io::stdout().flush() {
Ok(_) => return ExitCode::Ok, Ok(_) => return ExitCode::Ok,