1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#![no_std] mod cstr_core; extern crate alloc; use crate::alloc::borrow::ToOwned; use alloc::string::String; pub type CString = i32; pub fn cstr(s: &str) -> CString { cstr_core::CString::new(s).unwrap().into_raw() as i32 } pub fn cstr_to_string(c: impl Into<CString>) -> String { let s: &cstr_core::CStr = unsafe { cstr_core::CStr::from_ptr(c.into() as *const cstr_core::c_char) }; s.to_str().unwrap().to_owned() }