optimizations #161

Open
emma wants to merge 44 commits from optimizations into main
Showing only changes of commit ff4ff825bd - Show all commits

View File

@ -35,15 +35,9 @@ use strerror::StrError;
#[cfg(target_os="openbsd")] extern crate openbsd;
#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge };
fn oserr(argv0: &str, e: Error) -> ExitCode {
fn err(argv0: &str, e: Error, code: u8) -> ExitCode {
eprintln!("{}: {}", argv0, e.strerror());
ExitCode::from(EX_OSERR)
}
fn ioerr(argv0: &str, e: Error) -> ExitCode {
eprintln!("{}: {}", argv0, e.strerror());
ExitCode::from(EX_IOERR)
ExitCode::from(code)
}
fn usage(s: &str) -> ExitCode {
@ -57,7 +51,7 @@ fn main() -> ExitCode {
#[cfg(target_os="openbsd")] {
let promises = Promises::new("stdio");
if let Err(e) = pledge(Some(promises), None) {
return oserr(&argv[0], e);
return err(&argv[0], e, EX_OSERR);
}
}
@ -94,16 +88,16 @@ fn main() -> ExitCode {
if let Err(e) = output.write(&right)
.and_then(|_| output.write(&left)) {
break ioerr(&argv[0], e);
break err(&argv[0], e, EX_IOERR);
}
},
Ok(v) => { // partial read; partially write
if let Err(e) = output.write(&buf[..v]) {
break ioerr(&argv[0], e);
break err(&argv[0], e, EX_IOERR);
}
},
Err(e) => break oserr(&argv[0], e)
Err(e) => break err(&argv[0], e, EX_OSERR)
}
}
}