aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/mem.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-19 01:17:54 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-19 01:17:54 -0300
commit86b551fdf2a8bf5c6e3cebcc463ee830d65ced94 (patch)
tree2ea95245b5d1e82d8a7197206e2b640aa54119aa /src/utils/mem.c
parentfbc22f39090802845c3a046c3e10bae63d6af6cc (diff)
downloadblogc-86b551fdf2a8bf5c6e3cebcc463ee830d65ced94.tar.gz
blogc-86b551fdf2a8bf5c6e3cebcc463ee830d65ced94.tar.bz2
blogc-86b551fdf2a8bf5c6e3cebcc463ee830d65ced94.zip
safe mallocs are better :)
Diffstat (limited to 'src/utils/mem.c')
-rw-r--r--src/utils/mem.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/utils/mem.c b/src/utils/mem.c
new file mode 100644
index 0000000..04201ff
--- /dev/null
+++ b/src/utils/mem.c
@@ -0,0 +1,24 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file COPYING.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "utils.h"
+
+
+void*
+b_malloc(size_t size)
+{
+ // simple things simple!
+ void *rv = malloc(size);
+ if (rv == NULL) {
+ fprintf(stderr, "fatal error: Failed to allocate memory!\n");
+ exit(1);
+ }
+ return rv;
+}