summaryrefslogtreecommitdiff
path: root/memory.h
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-10-11 08:32:09 +0200
committertomsmeding <tom.smeding@gmail.com>2017-10-11 08:32:09 +0200
commit7549d07933091417b225d094c1648e1382287f93 (patch)
treef533b99745beb808d1cbe226a38e0232076d7b53 /memory.h
Initial
Diffstat (limited to 'memory.h')
-rw-r--r--memory.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/memory.h b/memory.h
new file mode 100644
index 0000000..9175dea
--- /dev/null
+++ b/memory.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <stdlib.h>
+
+#define malloc(num,type) \
+ ((type*)check_after_allocation("malloc",num,sizeof(type),malloc((num)*sizeof(type))))
+#define calloc(num,type) \
+ ((type*)check_after_allocation("calloc",num,sizeof(type),calloc((num),sizeof(type))))
+#define realloc(ptr,num,type) \
+ ((type*)check_after_allocation("realloc",num,sizeof(type),realloc((ptr),(num)*sizeof(type))))
+#define strdup(str) \
+ ((char*)check_after_allocation_str("strdup",strdup(str)))
+#define asprintf(...) \
+ (memory_asprintf_wrapper(__VA_ARGS__))
+
+void* check_after_allocation(const char *func,size_t num,size_t sz,void *ptr);
+void* check_after_allocation_str(const char *func,void *ptr);
+
+int memory_asprintf_wrapper(char **ret,const char *format,...) __attribute__((format (printf, 2, 3)));