summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'util.h')
-rw-r--r--util.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..d2f18c3
--- /dev/null
+++ b/util.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <stdbool.h> // this is useful
+
+
+#define malloc(n,t) ((t*)malloccheck((n)*sizeof(t)))
+#define calloc(n,t) ((t*)calloccheck((n),sizeof(t)))
+#define realloc(p,n,t) ((t*)realloccheck((p),(n)*sizeof(t)))
+
+#define mallocx(n,t) ((t*)mallocreal((n)*sizeof(t)))
+#define callocx(n,t) ((t*)callocreal((n),sizeof(t)))
+#define reallocx(p,n,t) ((t*)reallocreal((p),(n)*sizeof(t)))
+
+
+char* copystring(const char *s);
+char* copybufasstring(const char *b,int length);
+
+void outofmem(void) __attribute__((noreturn));
+
+void* malloccheck(size_t n);
+void* calloccheck(size_t n,size_t s);
+void* realloccheck(void *p,size_t n);
+
+void* mallocreal(size_t n);
+void* callocreal(size_t n,size_t s);
+void* reallocreal(void *p,size_t n);