aboutsummaryrefslogtreecommitdiffstats
path: root/src/utility.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utility.c')
-rw-r--r--src/utility.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utility.c b/src/utility.c
new file mode 100644
index 0000000..7000c02
--- /dev/null
+++ b/src/utility.c
@@ -0,0 +1,29 @@
+#include "utility.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+
+void *ctl_malloc(size_t size){
+ void *ptr = malloc(size);
+ if(ptr == NULL){
+ ctl_die(1);
+ }
+ return ptr;
+}
+void *ctl_realloc(void *ptr, size_t size){
+ ptr = realloc(ptr, size);
+ if(ptr == NULL){
+ ctl_die(1);
+ }
+ return ptr;
+}
+
+void ctl_die(ErrorType e){
+ switch(e){
+ case BAD_MEMORY:
+ fprintf(stderr, "exit: bad memory mananger\n");
+ break;
+ }
+ exit(e);
+}