50 lines
955 B
C
50 lines
955 B
C
#include <stdlib.h>
|
|
#include "malunal/allocator.h"
|
|
|
|
static
|
|
error_t
|
|
libc_allocator_acquire(
|
|
allocator_mptr_t allocator,
|
|
malunal_size_t size,
|
|
malunal_mptr_t* out
|
|
) {
|
|
MALUNAL_UNUSED(allocator);
|
|
|
|
*out = malloc(size);
|
|
return *out == null
|
|
? (error_t) {
|
|
.domain = &ERROR_DOMAIN_ALLOCATOR_T,
|
|
.code = ALLOCATOR_ERROR_OUT_OF_MEMORY
|
|
}
|
|
: NO_ERROR;
|
|
}
|
|
|
|
static
|
|
error_t
|
|
libc_allocator_dispose(
|
|
allocator_mptr_t allocator,
|
|
malunal_mptr_t address,
|
|
malunal_size_t size
|
|
) {
|
|
MALUNAL_UNUSED(allocator);
|
|
MALUNAL_UNUSED(size);
|
|
free(address);
|
|
return NO_ERROR;
|
|
}
|
|
|
|
static const
|
|
allocator_vtable_t libc_allocator_vtable = {
|
|
.acquire = (allocator_acquire_pfn_t)&libc_allocator_acquire,
|
|
.dispose = (allocator_dispose_pfn_t)&libc_allocator_dispose
|
|
};
|
|
|
|
static const
|
|
allocator_t libc_allocator_instance = {
|
|
.vtable = &libc_allocator_vtable
|
|
};
|
|
|
|
allocator_mptr_t
|
|
libc_allocator() {
|
|
return &libc_allocator_instance;
|
|
}
|