forked from PoliEcho-holding-org/kern
38 lines
697 B
C
38 lines
697 B
C
#include <stdlib.h>
|
||
#include <stddef.h>
|
||
#include <string.h>
|
||
#include <syscall.h>
|
||
|
||
void* malloc(size_t size) { return (void*)_malloc(size); }
|
||
|
||
void* calloc(size_t count, size_t size) {
|
||
size_t total = count * size;
|
||
void* ptr = malloc(total);
|
||
|
||
if (!ptr) { return NULL; }
|
||
memset(ptr, 0, total);
|
||
|
||
return ptr;
|
||
}
|
||
|
||
void* realloc(void* ptr, size_t size) {
|
||
if (size == 0) {
|
||
free(ptr);
|
||
return NULL;
|
||
}
|
||
|
||
if (ptr == NULL) { return malloc(size); }
|
||
|
||
void* newptr = malloc(size);
|
||
if (!newptr) { return NULL; }
|
||
|
||
// TODO: retrieve the old size
|
||
memcpy(newptr, ptr, size);
|
||
|
||
free(ptr);
|
||
return newptr;
|
||
}
|
||
|
||
void free(void* ptr) { _free(ptr); }
|
||
|