aboutsummaryrefslogtreecommitdiff
path: root/src/std/alloc.c
blob: 44a510572ae4e563076fb6237438bf62c7f0aff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "../../include/std/alloc.h"
#include "../../include/std/log.h"
#include <stdlib.h>

int am_malloc(usize size, void **mem) {
    void *allocated_data = malloc(size);
    if(!allocated_data) {
        amal_log_error("am_malloc: failed to allocate memory of size %lu", size);
        return ALLOC_FAIL;
    }
    
    *mem = allocated_data;
    return ALLOC_OK;
}

int am_realloc(void *mem, usize new_size, void **new_mem) {
    void *new_allocated_data = realloc(mem, new_size);
    if(!new_allocated_data && new_size != 0) {
        amal_log_error("am_malloc: failed to reallocate memory to size %lu", new_size);
        return ALLOC_FAIL;
    }
    
    *new_mem = new_allocated_data;
    return ALLOC_OK;
}

void am_free(void *mem) {
    free(mem);
}