aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--include/util.h2
-rw-r--r--src/util.c11
3 files changed, 15 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 3af9529..ff5c0c4 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,8 @@ OBJ = \
src/main.o \
src/parse.o \
src/type.o \
- src/utf8.o
+ src/utf8.o \
+ src/util.o
CFLAGS = -Iinclude
diff --git a/include/util.h b/include/util.h
index 2a1e72a..12829ef 100644
--- a/include/util.h
+++ b/include/util.h
@@ -6,4 +6,6 @@ enum exit_status {
EXIT_ABNORMAL = 255,
};
+void *must_malloc(size_t size);
+
#endif
diff --git a/src/util.c b/src/util.c
new file mode 100644
index 0000000..d34b722
--- /dev/null
+++ b/src/util.c
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+
+void *
+must_malloc(size_t size)
+{
+ void *ret = malloc(size);
+ if (ret == NULL) {
+ fprintf(stderr, "out of memory\n");
+ exit(EXIT_ABNORMAL);
+ }
+}