libopenbsd.rs(3): makes using statically-allocated arrays possible

This commit is contained in:
Emma Tebibyte 2024-09-11 02:32:03 -06:00
parent 800a097903
commit 0b3ed37c38
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -69,14 +69,12 @@ pub fn pledge(
pub struct UnveilPerms(CString); pub struct UnveilPerms(CString);
impl UnveilPerms { impl UnveilPerms {
pub fn new(permissions: Vec<char>) -> Self { pub fn new<T: IntoIterator<Item = char>>(permissions: T) -> Self {
if permissions.is_empty() { let perms = CString::new(
return UnveilPerms(CString::new("").unwrap()); permissions.into_iter().collect::<String>()
} ).unwrap();
UnveilPerms( UnveilPerms(perms)
CString::new(permissions.iter().collect::<String>()).unwrap()
)
} }
} }
@ -87,9 +85,9 @@ pub fn unveil(
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 c_char).unwrap_or(null()); let arg1 = path_c.map(|p| p.into_raw() as *const c_char).unwrap_or(null());
let arg2 = permissions let arg2 = permissions.map(|p| {
.map(|p| p.0.into_raw() as *const c_char) p.0.into_raw() as *const c_char
.unwrap_or(null()); }).unwrap_or(null());
unsafe { unsafe {
match openbsd::unveil(arg1, arg2) { match openbsd::unveil(arg1, arg2) {