aboutsummaryrefslogtreecommitdiff
path: root/src/alloc.c
blob: 282119fddc8ea651d1a4c9374cb251688d7bce22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "alloc.h"
#include <stdio.h>
#include <stdlib.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;
}