diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-12-23 23:45:54 +0100 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-12-23 23:45:54 +0100 |
commit | 14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6 (patch) | |
tree | 31b3d9a6f9f6144b08b852d016b5b4bdfce553ef /src/utils/mem.c | |
parent | 8e62072d91193b4894adda9c40544c18c1a01f57 (diff) | |
download | blogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.tar.gz blogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.tar.bz2 blogc-14e9d7b2299f15efb695b0202f9c1f6a9f7a4ba6.zip |
Revert "build: removing src/utils and replacing with squareball"
This reverts commit 950e6c9148eca244a89d18a21d4ae4e5c3d1c646.
Diffstat (limited to 'src/utils/mem.c')
-rw-r--r-- | src/utils/mem.c | 42 |
1 files changed, 42 insertions, 0 deletions
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 <rafael@rafaelmartins.eng.br> + * + * This program can be distributed under the terms of the BSD License. + * See the file LICENSE. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif /* HAVE_CONFIG_H */ + +#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; +} + + +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; +} |