mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
38 lines
696 B
C
38 lines
696 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); }
|
|
|