swab(1): uses pledge(2)
This commit is contained in:
parent
baa75a2619
commit
1003c82d23
12
src/swab.rs
12
src/swab.rs
@ -32,6 +32,10 @@ use getopt::GetOpt;
|
||||
use sysexits::{ EX_IOERR, EX_OK, EX_OSERR, EX_USAGE };
|
||||
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 {
|
||||
eprintln!("{}: {}", argv0, e.strerror());
|
||||
ExitCode::from(EX_OSERR as u8)
|
||||
@ -49,6 +53,14 @@ fn usage(s: &str) -> ExitCode {
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
|
||||
if cfg!(target_os="openbsd") {
|
||||
let promises = Promises::new("stdio");
|
||||
if let Err(e) = pledge(Some(promises), None) {
|
||||
return oserr(&argv[0], e);
|
||||
}
|
||||
}
|
||||
|
||||
let mut buf: Vec<u8> = Vec::new(); // holds the sequence getting swabbed
|
||||
let mut input = stdin();
|
||||
let mut output = stdout().lock();
|
||||
|
Loading…
Reference in New Issue
Block a user