Function nstd_sys::cstring::nstd_cstring_push_cstr
source · #[no_mangle]
pub unsafe extern "C" fn nstd_cstring_push_cstr(
cstring: &mut NSTDCString<'_>,
cstr: &NSTDCStr
) -> NSTDAllocErrorAvailable on crate feature
cstring only.Expand description
Appends a C string slice to the end of a C string.
Parameters:
-
NSTDCString *cstring- The C string. -
const NSTDCStr *cstr- The C string slice to append to the end ofcstring.
Returns
NSTDAllocError errc - The allocation operation error code.
Panics
This operation will panic in the following situations:
-
cstrcontains a null byte. -
Appending the new null byte to the end of the C string fails.
Safety
This operation can cause undefined behavior in the case that cstr’s data is invalid.
Example
use nstd_sys::{
alloc::{NSTDAllocError::NSTD_ALLOC_ERROR_NONE, NSTD_ALLOCATOR},
core::cstr::nstd_core_cstr_from_raw,
cstring::{nstd_cstring_new, nstd_cstring_push_cstr},
NSTDChar,
};
unsafe {
let mut cstring = nstd_cstring_new(&NSTD_ALLOCATOR).unwrap();
let cstr = nstd_core_cstr_from_raw("baNaNa\0".as_ptr().cast());
assert!(nstd_cstring_push_cstr(&mut cstring, &cstr) == NSTD_ALLOC_ERROR_NONE);
}