summaryrefslogtreecommitdiffstats
path: root/safe_libc/src/util.rs
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2020-04-04 13:22:18 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2020-04-04 14:23:00 +0200
commitf0b3d5166ef1255fac880b146875ef46d2599a13 (patch)
tree61c993cf32dedc1172bcf40cd5207e05a3b032a9 /safe_libc/src/util.rs
parent52b498494534784c77bfa4a93706be40620ebd9a (diff)
downloadneco-f0b3d5166ef1255fac880b146875ef46d2599a13.tar
neco-f0b3d5166ef1255fac880b146875ef46d2599a13.zip
Reorganize
Diffstat (limited to 'safe_libc/src/util.rs')
-rw-r--r--safe_libc/src/util.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/safe_libc/src/util.rs b/safe_libc/src/util.rs
new file mode 100644
index 0000000..b8a4ed5
--- /dev/null
+++ b/safe_libc/src/util.rs
@@ -0,0 +1,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
+}