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);