use std::ffi::{CString, c_char, c_int};
use std::os::unix::ffi::OsStrExt;
use std::path::Path;
unsafe extern "C" {
fn sandbox_check(pid: c_int, operation: *const c_char, kind: c_int, ...) -> c_int;
}
const NONE: c_int = 0;
const PATH: c_int = 1;
fn pid() -> c_int {
std::process::id() as c_int
}
pub fn sandboxed() -> bool {
unsafe { sandbox_check(pid(), std::ptr::null(), NONE) == 1 }
}
pub fn denies(operation: &str, path: &Path) -> bool {
let (Ok(op), Ok(path)) = (
CString::new(operation),
CString::new(path.as_os_str().as_bytes()),
) else {
return false;
};
unsafe { sandbox_check(pid(), op.as_ptr(), PATH, path.as_ptr()) == 1 }
}