Copies the capabilities C-string into a fixed buffer and returns it. The returned SmallCString is guaranteed to be null-terminated.
(caps: u32)
| 818 | /// Copies the capabilities C-string into a fixed buffer and returns it. |
| 819 | /// The returned SmallCString is guaranteed to be null-terminated. |
| 820 | pub(crate) fn capabilities_from_enum(caps: u32) -> SmallCString { |
| 821 | let caps_ptr = unsafe { sz_capabilities_to_string(caps) }; |
| 822 | // Assume that the external function returns a valid null-terminated C string. |
| 823 | let cstr = unsafe { CStr::from_ptr(caps_ptr as *const c_char) }; |
| 824 | let bytes = cstr.to_bytes(); |
| 825 | |
| 826 | let mut buf = SmallCString::new(); |
| 827 | // Use core::fmt::Write to copy the bytes. |
| 828 | // If the string is too long, it will fail. You might want to truncate in a real-world use. |
| 829 | // Here, we assume it fits. |
| 830 | let s = core::str::from_utf8(bytes).unwrap_or(""); |
| 831 | let _ = buf.write_str(s); |
| 832 | buf |
| 833 | } |
| 834 | |
| 835 | /// Copies the capabilities C-string into a fixed buffer and returns it. |
| 836 | /// The returned SmallCString is guaranteed to be null-terminated. |
no test coverage detected
searching dependent graphs…