1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
use std::ffi::CStr;

pub type CString = i32;

pub fn cstr(s: &str) -> CString {
    std::ffi::CString::new(s).unwrap().into_raw() as i32
}

pub fn cstr_to_string(c: CString) -> String {
    let s: &CStr = unsafe { CStr::from_ptr(c as *const i8) };
    s.to_str().unwrap().to_owned()
}