1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
extern crate libc; #[cfg(target_os = "openbsd")] mod openbsd; #[derive(Debug, PartialEq)] pub enum Error { NotSupported, Os(i32), } #[cfg(target_os = "openbsd")] pub fn unveil(path: &str, permissions: &str) -> Result<(), Error> { openbsd::unveil(path, permissions).map_err(Error::Os) } #[cfg(not(target_os = "openbsd"))] #[allow(unused_variables)] pub fn unveil(path: &str, permissions: &str) -> Result<(), Error> { return Err(Error::NotSupported); } #[cfg(test)] mod tests { use *; #[test] #[cfg(target_os = "openbsd")] fn test_unveil() { assert!(unveil(".", "r").is_ok()); } #[test] #[cfg(target_os = "openbsd")] fn test_unveil_restrict() { assert!(unveil("", "").is_ok()); assert!(unveil(".", "r").is_err()); } #[test] #[cfg(not(target_os = "openbsd"))] fn test_unveil_not_supported() { assert_eq!(unveil(".", "r").unwrap_err(), Error::NotSupported); } }