#[unsafe(no_mangle)]pub unsafe extern "C" fn nstd_core_mem_compare(
buf1: *const NSTDByte,
buf2: *const NSTDByte,
num: NSTDUInt,
) -> NSTDBoolAvailable on crate feature
core only.Expand description
Compares two memory buffers of num bytes.
§Parameters:
-
const NSTDByte *buf1- A pointer to the first memory buffer. -
const NSTDByte *buf2- A pointer to the second memory buffer. -
NSTDUInt num- The number of bytes to compare.
§Returns
NSTDBool is_eq - NSTD_TRUE if the memory buffers carry the same data.
§Safety
-
This function is highly unsafe as it does not know how large either of the memory buffers actually are, which can lead to undefined behavior if either of the buffers’ length are less than
num. -
buf1andbuf2must be non-null.
§Example
use nstd_sys::{
core::mem::{nstd_core_mem_compare, nstd_core_mem_copy},
NSTD_TRUE,
};
let buf1 = [0u32; 12];
let mut buf2 = [u32::MAX; 12];
let num = core::mem::size_of::<[u32; 12]>();
let ptr1 = buf1.as_ptr().cast();
let ptr2 = buf2.as_mut_ptr().cast();
unsafe {
nstd_core_mem_copy(ptr2, ptr1, num);
assert!(nstd_core_mem_compare(ptr1, ptr2, num) == NSTD_TRUE);
}