summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpacien2017-12-02 01:07:20 +0100
committerpacien2017-12-02 01:07:20 +0100
commitc65669a785fba9b1f0f7539f47a677035ea06229 (patch)
tree8ba94389479b1bef7bd2bd07fddbc38bedfad569 /src
parent1c75b9dca56f4879798d9c9a5b9c48428e117448 (diff)
downloadmorpher-c65669a785fba9b1f0f7539f47a677035ea06229.tar.gz
Add some common utility functions
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src')
-rw-r--r--src/common/error.c8
-rw-r--r--src/common/mem.c12
2 files changed, 20 insertions, 0 deletions
diff --git a/src/common/error.c b/src/common/error.c
new file mode 100644
index 0000000..f28a6cd
--- /dev/null
+++ b/src/common/error.c
@@ -0,0 +1,8 @@
1#include "common/error.h"
2#include <stdlib.h>
3#include <stdio.h>
4
5void rage_quit(const char *msg) {
6 fprintf(stderr, "FATAL ERROR: %s\n", msg);
7 exit(1);
8}
diff --git a/src/common/mem.c b/src/common/mem.c
new file mode 100644
index 0000000..855e010
--- /dev/null
+++ b/src/common/mem.c
@@ -0,0 +1,12 @@
1#include "common/mem.h"
2#include <stdlib.h>
3#include "common/error.h"
4
5void *malloc_or_die(size_t size) {
6 void *ptr = malloc(size);
7
8 if (ptr == NULL)
9 rage_quit(OUT_OF_MEMORY_ERROR);
10
11 return ptr;
12}