libc::strlen
RS-W1098The length of CString
s may be calculated with .as_bytes().len()
, which is
safe and performant, as compared to libc::strlen
, which is an unsafe
operation.
The following alternatives are preferred:
CString
s, .as_bytes().len()
CStr
s, .to_bytes().len()
let my_string = CString::new("foo").expect("CString::new failed");
let length = unsafe {
libc::strlen(my_string.as_ptr())
};
let my_string = CString::new("foo").expect("CString::new failed");
let length = my_string.as_bytes().len();