1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
use std::ffi::{c_char, CString};
/// Free a string.
///
/// # Safety
/// The argument must be a string pointer or NULL.
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_str_free(s: *mut c_char) {
if !s.is_null() {
unsafe { drop(CString::from_raw(s)) };
}
}
/// Free an array of strings.
///
/// # Safety
/// The argument must be a pointer to a string array or NULL along with the length of the array.
#[no_mangle]
pub unsafe extern "C" fn pkgcraft_str_array_free(strs: *mut *mut c_char, len: usize) {
if !strs.is_null() {
unsafe {
for s in Vec::from_raw_parts(strs, len, len).into_iter() {
drop(CString::from_raw(s));
}
}
}
}