From 0b3ed37c380fd9f44be686fbdad5cf02f3429964 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 11 Sep 2024 02:32:03 -0600 Subject: [PATCH] libopenbsd.rs(3): makes using statically-allocated arrays possible --- src/libopenbsd.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/libopenbsd.rs b/src/libopenbsd.rs index 613aa68..2557dd8 100644 --- a/src/libopenbsd.rs +++ b/src/libopenbsd.rs @@ -69,14 +69,12 @@ pub fn pledge( pub struct UnveilPerms(CString); impl UnveilPerms { - pub fn new(permissions: Vec) -> Self { - if permissions.is_empty() { - return UnveilPerms(CString::new("").unwrap()); - } - - UnveilPerms( - CString::new(permissions.iter().collect::()).unwrap() - ) + pub fn new>(permissions: T) -> Self { + let perms = CString::new( + permissions.into_iter().collect::() + ).unwrap(); + + UnveilPerms(perms) } } @@ -87,9 +85,9 @@ pub fn unveil( 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 arg2 = permissions - .map(|p| p.0.into_raw() as *const c_char) - .unwrap_or(null()); + let arg2 = permissions.map(|p| { + p.0.into_raw() as *const c_char + }).unwrap_or(null()); unsafe { match openbsd::unveil(arg1, arg2) {