libopenbsd.rs(3): fixes API for unveil(2)
This commit is contained in:
parent
eae0b0352b
commit
70bec49127
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
use std::{
|
||||
ffi::{ CString, c_int },
|
||||
ffi::CString,
|
||||
io::Error,
|
||||
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 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)
|
||||
.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 */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user