created why2_recalloc fn in memory

deallocates and callocs
This commit is contained in:
Václav Šmejkal 2024-11-21 16:52:06 +01:00
parent 0e246be627
commit c5394e63e5
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 13 additions and 1 deletions

View File

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

View File

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