sinf 0.1.0

Library for obtaining in-depth system information at both the hardware and software levels
Documentation
/// Reads the value of a kernel environment variable.
pub(crate) fn get_kenv_var(name: &[u8]) -> Option<String> {
    let mut buf: [libc::c_char; libc::KENV_MVALLEN as usize] = [0; libc::KENV_MVALLEN as usize];

    let size = unsafe {
        libc::kenv(
            libc::KENV_GET as _,
            name.as_ptr() as _,
            buf.as_mut_ptr() as _,
            buf.len() as _,
        ) as isize
    };

    // Returns a strictly negative number on error.
    if size < 0 {
        return None;
    }

    super::strings::c_buf_to_utf8_string(&buf[..size as usize])
}