INNER CODE UNIT · Rust

Some

domcyrus/rustnet · crates/rustnet-host/src/lib.rs:397

    if let Some(owner) = cache.get(key) {
        return Some((owner.clone(), MatchQuality::ExactTuple));
    }
    relaxed_lookup(cache, key).map(|(owner, quality)| (owner.clone(), quality))
}

/// Decode a NUL-terminated C char array (`ki_comm`, `pbi_comm`, ...) into a
/// process name. `None` when the array is empty.
#[cfg(any(target_os = "freebsd", target_os = "macos"))]
pub(crate) fn decode_process_name(chars: &[libc::c_char]) -> Option<String> {
    let bytes: Vec<u8> = chars
        .iter()
        .copied()
        .take_while(|value| *value != 0)
        .map(|value| value as u8)
        .collect();
    (!bytes.is_empty()).then(|| String::from_utf8_lossy(&bytes).into_owned())
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…