use doors::illumos::door_h;
use doors::illumos::stropts_h;
use libc;
use std::ffi::{CStr, CString};
use std::fs;
use std::path::Path;
use std::ptr;
extern "C" fn capitalize_string(
_cookie: *const libc::c_void,
argp: *const libc::c_char,
arg_size: libc::size_t,
_dp: *const door_h::door_desc_t,
_n_desc: libc::c_uint,
) {
let original = unsafe { CStr::from_ptr(argp) };
let original = original.to_str().unwrap();
let capitalized = original.to_ascii_uppercase();
let capitalized = CString::new(capitalized).unwrap();
unsafe {
door_h::door_return(capitalized.as_ptr(), arg_size, ptr::null(), 0)
};
}
fn main() {
let door_path = Path::new("/tmp/barebones_capitalize.door");
if door_path.exists() {
fs::remove_file(door_path).unwrap();
}
let door_path_cstring = CString::new(door_path.to_str().unwrap()).unwrap();
unsafe {
let server_door_fd =
door_h::door_create(capitalize_string, ptr::null(), 0);
fs::File::create(door_path).unwrap();
stropts_h::fattach(server_door_fd, door_path_cstring.as_ptr());
}
std::thread::sleep(std::time::Duration::from_secs(5));
}