yac
/
coreutils
Archived
2
0
Fork 0

cat(1): -u works, kinda, but requires 3 ctrl+D presses

This commit is contained in:
Emma Tebibyte 2022-12-17 17:48:07 -05:00
parent cc64ab08da
commit 20e9c19ccd
1 changed files with 29 additions and 3 deletions

View File

@ -18,10 +18,9 @@
*/
use std::env;
use std::fs::{File, read, read_to_string};
use std::fs::{File, read_to_string};
use std::io;
use std::io::{ Read, Write };
use std::os::unix::io::FromRawFd;
use std::io::{ BufRead, Read };
use std::str;
use arg::Args;
@ -50,6 +49,33 @@ fn main() -> ExitCode {
if args.paths.is_empty() { args.paths.push("-".to_string()); }
while args.u {
for path in &args.paths {
if path == "-" {
loop {
let mut buf = String::new();
match io::stdin().lock().read_line(&mut buf) {
Ok(bytes) => {
if bytes == 0 { break };
print!("{}", buf);
},
Err(err) => println!("{}", err),
};
}
} else {
let mut input = String::new();
match File::open(path) {
Ok(input) => {},
Err(_) => {
println!("{}: {}: No such file or directory.", &argv0, path);
return ExitCode::NoInput;
},
};
}
}
return ExitCode::Ok;
}
for path in args.paths {
if path == "-" {
let mut bytes: Vec<u8> = Vec::new();