libopenbsd.rs(3): fixes API for unveil(2)

This commit is contained in:
Emma Tebibyte 2024-08-10 13:25:56 -06:00
parent eae0b0352b
commit 70bec49127
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -17,7 +17,7 @@
*/ */
use std::{ use std::{
ffi::{ CString, c_int }, ffi::CString,
io::Error, io::Error,
ptr::null, ptr::null,
}; };
@ -76,7 +76,10 @@ impl UnveilPerms {
} }
} }
pub fn unveil(path: Option<&str>, permissions: Option<UnveilPerms>) -> c_int { pub fn unveil(
path: Option<&str>,
permissions: Option<UnveilPerms>,
) -> Result<(), Error> {
let path_c = path.map(CString::new).map(Result::unwrap); let path_c = path.map(CString::new).map(Result::unwrap);
let arg1 = path_c.map(|p| p.into_raw() as *const i8).unwrap_or(null()); let arg1 = path_c.map(|p| p.into_raw() as *const i8).unwrap_or(null());
@ -84,5 +87,11 @@ pub fn unveil(path: Option<&str>, permissions: Option<UnveilPerms>) -> c_int {
.map(|p| p.0.into_raw() as *const i8) .map(|p| p.0.into_raw() as *const i8)
.unwrap_or(null()); .unwrap_or(null());
unsafe { openbsd::unveil(arg1, arg2) } unsafe {
match openbsd::unveil(arg1, arg2) {
-1 => Err(Error::from_raw_os_error(*openbsd::__errno())),
0 => Ok(()),
_ => panic!(), /* unreachable */
}
}
} }