summaryrefslogtreecommitdiffstats
path: root/safe_libc/src/util.rs
blob: b8a4ed50062a06541a29983225b6ad793fd4b5c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use core::mem;

#[inline]
pub fn zst<T>(len: usize) -> bool {
	mem::size_of::<T>() == 0 || len == 0
}

#[inline]
pub fn check_ptr<T>(p: *const T, len: usize) {
	debug_assert!((p as usize) % mem::align_of::<T>() == 0, "unaligned ptr");
	assert!(zst::<T>(len) || !p.is_null(), "NULL ptr");
}

#[inline]
pub fn must_succeed<T>(p: *mut T) -> *mut T {
	assert!(!p.is_null(), "allocation failure");
	p
}