summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2016-08-18 20:52:28 +0200
committertomsmeding <tom.smeding@gmail.com>2016-08-18 20:52:28 +0200
commit2c30522aa65126ebacfd52f7b38a2e24682d7065 (patch)
tree12baf2dfe17cc86f3c9711a700f6f9bbd3764275 /util.h
parent235ffca9db0c2ba0d1ecbc79bdfb3dcdfca939c7 (diff)
Second
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);