#include "MemoryManager.h"
#include <stdlib.h>

Result std_alloc(MemoryManager mm, void** ptr, usize size) {
    *ptr = malloc(size);
    return (*ptr == NULL) ? R_Err : R_Ok;
}

Result std_realloc(MemoryManager mm, void** ptr, usize size) {
    *ptr = realloc(*ptr, size);
    return (*ptr == NULL) ? R_Err : R_Ok;
}

Result std_free(MemoryManager mm, void** ptr) {
    free(*ptr);
    *ptr = NULL;
    return R_Ok;
}

Result std_destroy(MemoryManager *mm) {
    return R_Unavailable;
}

MemoryManager M_std() {
    return (MemoryManager){
        .alloc = &std_alloc,
        .realloc = &std_realloc,
        .free = &std_free,
        .destroy = &std_destroy,
    };
}
