cat(1): cleanup
This commit is contained in:
parent
ad45829309
commit
c5123b9d19
18
src/cat.rs
18
src/cat.rs
@ -35,20 +35,6 @@ struct Arguments {
|
||||
paths: Vec<String>,
|
||||
}
|
||||
|
||||
fn out(argv0: &str, u: bool, val: &str) -> ExitCode {
|
||||
if u {
|
||||
let mut stdout = unsafe { File::from_raw_fd(1) };
|
||||
match stdout.write_all(val.as_bytes()) {
|
||||
Ok(_) => {},
|
||||
Err(_) => {
|
||||
eprintln!("{}: Cannot write to stdout", argv0);
|
||||
return ExitCode::OsErr;
|
||||
},
|
||||
};
|
||||
} else { print!("{}", val); }
|
||||
ExitCode::Ok
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let mut arguments = env::args().collect::<Vec<String>>();
|
||||
let argv0 = arguments.remove(0);
|
||||
@ -68,7 +54,7 @@ fn main() -> ExitCode {
|
||||
loop {
|
||||
match io::stdin().lock().read_line(&mut output) {
|
||||
Ok(EOF) => {
|
||||
out(&argv0, args.u, &output);
|
||||
print!("{}", output);
|
||||
output.clear();
|
||||
if EOF == 0 { break }
|
||||
},
|
||||
@ -80,7 +66,7 @@ fn main() -> ExitCode {
|
||||
}
|
||||
} else {
|
||||
match read_to_string(&path) {
|
||||
Ok(output) => { out(&argv0, args.u, &output); },
|
||||
Ok(output) => print!("{}", output),
|
||||
Err(_) => {
|
||||
eprintln!("{}: {}: No such file or directory.", &argv0, &path);
|
||||
return ExitCode::NoInput;
|
||||
|
Reference in New Issue
Block a user