| 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. |