#[no_mangle]
pub unsafe extern "C" fn nstd_cstring_from_cstr(
    cstr: &NSTDCStr
) -> NSTDCString
Available on crate feature nstd_cstring only.
Expand description

Creates an owned version of an unowned C string slice.

Parameters:

  • const NSTDCStr *cstr - The unowned C string slice.

Returns

NSTDCString cstring The new owned version of cstr.

Panics

This operation will panic in the following situations:

  • cstr contains a null byte.

  • cstr’s length is greater than NSTDInt’s max value.

  • Allocating fails.

Safety

The caller of this function must ensure that cstr’s data is valid for reads.

Example

use nstd_sys::{core::cstr::nstd_core_cstr_from_raw, cstring::nstd_cstring_from_cstr};

unsafe {
    let cstr = nstd_core_cstr_from_raw("C string\0".as_ptr().cast());
    let cstring = nstd_cstring_from_cstr(&cstr);
}