diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-07-13 15:59:30 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-13 15:59:30 +0200 |
commit | ae0520e57267dbd866fc8cd25f66f4e6af2ac118 (patch) | |
tree | 22788688f1b588c3ad00c1ce3fe13da68b3a9382 /src/alloc.c | |
parent | a1ca82847eb356c6b85ada2ac11f38d98f6e085e (diff) |
Move c files into src directory
Diffstat (limited to 'src/alloc.c')
-rw-r--r-- | src/alloc.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c new file mode 100644 index 0000000..dca69b5 --- /dev/null +++ b/src/alloc.c @@ -0,0 +1,20 @@ +#include "alloc.h" +#include <stdio.h> + +void* alloc_or_crash(size_t size) { + void *mem = malloc(size); + if(!mem) { + fprintf(stderr, "Error: failed to allocate %zu bytes\n", size); + abort(); + } + return mem; +} + +void* realloc_or_crash(void *mem, size_t new_size) { + void *new_mem = realloc(mem, new_size); + if(!new_mem) { + fprintf(stderr, "Error: failed to reallocate %p to size %zu\n", mem, new_size); + abort(); + } + return new_mem; +} |