ensc_libc_util/
lib.rs

1
2
3
4
5
6
7
8
9
10
mod fd;

pub use fd::Fd;

pub fn c_string_to_str(s: &[libc::c_char]) -> &str {
    let pos = s.iter().position(|c| *c == 0).unwrap_or(s.len());
    let s = unsafe { core::slice::from_raw_parts(s.as_ptr() as * const _, pos) };

    core::str::from_utf8(s).unwrap()
}