cat(1): fixed pseudo-unbuffered output
This commit is contained in:
parent
c5123b9d19
commit
3e555542b6
10
src/cat.rs
10
src/cat.rs
@ -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,
|
||||||
|
Reference in New Issue
Block a user