From c5394e63e50e7c2e018a4323d33821c4f4e14884 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Thu, 21 Nov 2024 16:52:06 +0100 Subject: [PATCH] created why2_recalloc fn in memory deallocates and callocs --- include/memory.h | 3 ++- src/core/lib/utils/memory.c | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/memory.h b/include/memory.h index 5a2902c..76bb504 100644 --- a/include/memory.h +++ b/include/memory.h @@ -27,7 +27,8 @@ extern "C" { void *why2_malloc(unsigned long size); void *why2_calloc(unsigned long element, unsigned long size); -void *why2_realloc(void *pointer, unsigned long size); +void *why2_realloc(void *pointer, unsigned long size); //THIS DOESN'T PRESERVE CONTENT OF pointer! +void *why2_recalloc(void *pointer, unsigned long size, unsigned long block_size); //SAME AS why2_realloc BUT FILLS THE pointer WITH NULL-TERMS char *why2_strdup(char *string); diff --git a/src/core/lib/utils/memory.c b/src/core/lib/utils/memory.c index e766566..31e5612 100644 --- a/src/core/lib/utils/memory.c +++ b/src/core/lib/utils/memory.c @@ -153,6 +153,17 @@ void *why2_realloc(void *pointer, unsigned long size) return allocated; } +void *why2_recalloc(void *pointer, unsigned long size, unsigned long block_size) +{ + if (pointer != NULL) why2_deallocate(pointer); + + void *allocated = calloc(size, block_size); + + push_to_list(allocated, ALLOCATION); + + return allocated; +} + char *why2_strdup(char *string) { char *allocated = strdup(string);