diff --git a/src/hru.rs b/src/hru.rs index 1ed5bdd..c6009a7 100644 --- a/src/hru.rs +++ b/src/hru.rs @@ -29,6 +29,10 @@ extern crate sysexits; use strerror::StrError; use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE, EX_USAGE }; +#[cfg(target_os="openbsd")] use sysexits::EX_OSERR; +#[cfg(target_os="openbsd")] extern crate openbsd; +#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge }; + /* list of SI prefixes */ const LIST: [(u32, &str); 10] = [ (3, "k"), /* kilo */ @@ -76,10 +80,20 @@ fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> { fn main() -> ExitCode { let argv = args().collect::>(); + if let Some(_) = argv.get(1) { eprintln!("Usage: {}", argv[0]); return ExitCode::from(EX_USAGE as u8); } + + if cfg!(target_os="openbsd") { + let promises = Promises::new("stdio"); + if let Err(e) = pledge(Some(promises), None) { + eprintln!("{}: {}", argv[0], e.strerror()); + return ExitCode::from(EX_OSERR as u8); + } + } + let mut buf = String::new(); while let Ok(_) = stdin().read_line(&mut buf) {