hru(1): adds support for pledge(2)

This commit is contained in:
Emma Tebibyte 2024-08-10 13:34:44 -06:00
parent 2f805cc942
commit bda7c074b0
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -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::<Vec<String>>();
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) {