hru(1): adds support for pledge(2)
This commit is contained in:
parent
2f805cc942
commit
bda7c074b0
14
src/hru.rs
14
src/hru.rs
@ -29,6 +29,10 @@ extern crate sysexits;
|
|||||||
use strerror::StrError;
|
use strerror::StrError;
|
||||||
use sysexits::{ EX_DATAERR, EX_IOERR, EX_SOFTWARE, EX_USAGE };
|
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 */
|
/* list of SI prefixes */
|
||||||
const LIST: [(u32, &str); 10] = [
|
const LIST: [(u32, &str); 10] = [
|
||||||
(3, "k"), /* kilo */
|
(3, "k"), /* kilo */
|
||||||
@ -76,10 +80,20 @@ fn convert(input: u128) -> Result<(f64, (u32, &'static str)), String> {
|
|||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
|
|
||||||
if let Some(_) = argv.get(1) {
|
if let Some(_) = argv.get(1) {
|
||||||
eprintln!("Usage: {}", argv[0]);
|
eprintln!("Usage: {}", argv[0]);
|
||||||
return ExitCode::from(EX_USAGE as u8);
|
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();
|
let mut buf = String::new();
|
||||||
|
|
||||||
while let Ok(_) = stdin().read_line(&mut buf) {
|
while let Ok(_) = stdin().read_line(&mut buf) {
|
||||||
|
Loading…
Reference in New Issue
Block a user