From 326c8f77d13683dd3e3aae5cb2cdd75993857efe Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 10 Aug 2024 15:34:14 -0600 Subject: [PATCH] rpn(1): adds support for pledge(2) --- src/rpn.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/rpn.rs b/src/rpn.rs index 784e323..e4f725d 100644 --- a/src/rpn.rs +++ b/src/rpn.rs @@ -56,6 +56,12 @@ extern crate sysexits; use sysexits::EX_DATAERR; +#[cfg(target_os="openbsd")] use sysexits::EX_OSERR; +#[cfg(target_os="openbsd")] extern crate strerror; +#[cfg(target_os="openbsd")] extern crate openbsd; +#[cfg(target_os="openbsd")] use strerror::StrError; +#[cfg(target_os="openbsd")] use openbsd::{ Promises, pledge }; + #[derive(Clone, PartialEq, PartialOrd, Debug)] /* enum CalcType is a type containing operations used in the calculator */ enum CalcType { @@ -191,6 +197,15 @@ fn round_precise(value: &f64, precision: usize) -> f64 { fn main() -> ExitCode { let argv = args().collect::>(); + + 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 stack = VecDeque::new(); let mut buf = String::new(); /* Set floating-point precision for correcting rounding errors based on