nstd_cstring_push_cstr

Function nstd_cstring_push_cstr 

Source
#[unsafe(no_mangle)]
pub unsafe extern "C" fn nstd_cstring_push_cstr( cstring: &mut NSTDCString<'_>, cstr: &NSTDCStr, ) -> NSTDAllocError
Available 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 of cstring.

§Returns

NSTDAllocError errc - The allocation operation error code.

§Panics

This operation will panic in the following situations:

  • cstr contains 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::NSTD_ALLOCATOR,
    core::{alloc::NSTDAllocError::NSTD_ALLOC_ERROR_NONE, 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);
}