diff --git a/src/libopenbsd.rs b/src/libopenbsd.rs index 7d98d10..c16c51c 100644 --- a/src/libopenbsd.rs +++ b/src/libopenbsd.rs @@ -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) -> c_int { +pub fn unveil( + path: Option<&str>, + permissions: Option, +) -> 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) -> 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 */ + } + } }