From 86b551fdf2a8bf5c6e3cebcc463ee830d65ced94 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sun, 19 Apr 2015 01:17:54 -0300 Subject: safe mallocs are better :) --- src/utils/mem.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/utils/mem.c (limited to 'src/utils/mem.c') 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 + * + * This program can be distributed under the terms of the BSD License. + * See the file COPYING. + */ + +#include +#include +#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; +} -- cgit v1.2.3-18-g5258