use ::std::{
alloc::{GlobalAlloc, Layout},
ffi::CString,
str::FromStr as _,
};
struct MyAlloc;
#[global_allocator]
static ALLOCATOR: MyAlloc = MyAlloc;
unsafe impl GlobalAlloc for MyAlloc {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
unsafe { libc::malloc(layout.size()) as *mut u8 }
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
unsafe { libc::free(ptr.cast()) }
}
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let align = layout.align();
let nmemb = (layout.size() + align - 1) >> align.trailing_zeros();
unsafe { libc::calloc(nmemb, align) as *mut u8 }
}
unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, new_size: usize) -> *mut u8 {
unsafe { libc::realloc(ptr.cast(), new_size) as *mut u8 }
}
}
fn main() {
let args = std::env::args().collect::<Vec<String>>();
let args = args
.into_iter()
.map(|s| CString::from_str(&s).unwrap())
.collect::<Vec<CString>>();
let mut args: Vec<*mut u8> = args.into_iter().map(|s| s.into_raw().cast()).collect();
unsafe {
ztmux::tmux_main(
args.len() as i32,
args.as_mut_slice().as_mut_ptr(),
std::ptr::null_mut(),
);
}
drop(
args.into_iter()
.map(|ptr| unsafe { CString::from_raw(ptr.cast()) }),
);
}