MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / path_with_termination

Method path_with_termination

src/backend/linux_raw/net/addr.rs:122–131  ·  view source on GitHub ↗
(bytes: &[u8])

Source from the content-addressed store, hash-verified

120 #[cfg(feature = "alloc")]
121 #[cold]
122 unsafe fn path_with_termination(bytes: &[u8]) -> Option<Cow<'_, CStr>> {
123 let mut owned = Vec::with_capacity(bytes.len() + 1);
124 owned.extend_from_slice(bytes);
125 owned.push(b'\0');
126 // SAFETY: `from_vec_with_nul_unchecked` since the string is
127 // NUL-terminated and `bytes` does not contain any NULs.
128 Some(Cow::Owned(
129 CString::from_vec_with_nul_unchecked(owned).into(),
130 ))
131 }
132
133 /// For a filesystem path address, return the path as a byte sequence,
134 /// excluding the NUL terminator.

Callers

nothing calls this directly

Calls 2

pushMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected