Wrote value, chunk, memory sections, tested value

chunk and memory remain untested for now
This commit is contained in:
2024-08-13 23:42:14 +10:00
parent 190294e5d9
commit e6ad46f1ff
11 changed files with 204 additions and 10 deletions

22
source/toy_memory.c Normal file
View File

@@ -0,0 +1,22 @@
#include "toy_memory.h"
#include "toy_console_colors.h"
#include <stdio.h>
#include <stdlib.h>
void* Toy_reallocate(void* pointer, size_t oldSize, size_t newSize) {
if (newSize == 0) {
free(pointer);
return NULL;
}
void* result = realloc(pointer, newSize);
if (result == NULL) {
fprintf(stderr, TOY_CC_ERROR "[internal] ERROR: Memory allocation error (requested %d, replacing %d)\n" TOY_CC_RESET, (int)newSize, (int)oldSize);
exit(1);
}
return result;
}