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

This commit is contained in:
Emma Tebibyte 2024-08-10 15:34:14 -06:00
parent 72ef8d00bc
commit 326c8f77d1
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -56,6 +56,12 @@ extern crate sysexits;
use sysexits::EX_DATAERR; 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)] #[derive(Clone, PartialEq, PartialOrd, Debug)]
/* enum CalcType is a type containing operations used in the calculator */ /* enum CalcType is a type containing operations used in the calculator */
enum CalcType { enum CalcType {
@ -191,6 +197,15 @@ fn round_precise(value: &f64, precision: usize) -> f64 {
fn main() -> ExitCode { fn main() -> ExitCode {
let argv = args().collect::<Vec<String>>(); let argv = args().collect::<Vec<String>>();
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 stack = VecDeque::new();
let mut buf = String::new(); let mut buf = String::new();
/* Set floating-point precision for correcting rounding errors based on /* Set floating-point precision for correcting rounding errors based on