blob: dca69b57bad63ce3341d87cce3962ae069b442d4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
}
|