From 14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 23 Dec 2015 23:45:54 +0100 Subject: Revert "build: removing src/utils and replacing with squareball" This reverts commit 950e6c9148eca244a89d18a21d4ae4e5c3d1c646. --- src/utils/mem.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 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..7c5e0a2 --- /dev/null +++ b/src/utils/mem.c @@ -0,0 +1,42 @@ +/* + * 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 LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif /* HAVE_CONFIG_H */ + +#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; +} + + +void* +b_realloc(void *ptr, size_t size) +{ + // simple things even simpler :P + void *rv = realloc(ptr, size); + if (rv == NULL && size != 0) { + fprintf(stderr, "fatal error: Failed to reallocate memory!\n"); + free(ptr); + exit(1); + } + return rv; +} -- cgit v1.2.3-18-g5258