INNER CODE UNIT · Rust

to_c_string

elringus/sprite-dicing · crates/abi/src/lib.rs:243

fn to_c_string(str: &str) -> CString {
    CString::new(str).unwrap_or_default()
}

fn to_c_str(str: &str) -> *const c_char {
    to_c_string(str).into_raw()
}

unsafe fn free_c_str(ptr: *const c_char) {
    if !ptr.is_null() {
        drop(CString::from_raw(ptr as *mut c_char));
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::ffi::c_void;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…