feat: added memchr, memcmp, memmv and realloc

This commit is contained in:
Zoëy Noort 2025-05-31 19:37:00 +02:00
parent 3287cd402f
commit 0f35f48c25
4 changed files with 129 additions and 0 deletions

22
srcs/ft_realloc.c Normal file
View file

@ -0,0 +1,22 @@
#include "libft.h"
#include <stdlib.h>
#include <string.h>
void *ft_realloc(void *ptr, size_t old_size, size_t new_size)
{
if (new_size == 0) {
free(ptr);
return (NULL);
}
if (!ptr)
return (malloc(new_size));
void *new_ptr = malloc(new_size);
if (!new_ptr)
return (NULL);
size_t copy_size = old_size < new_size ? old_size : new_size;
ft_memcpy(new_ptr, ptr, copy_size);
free(ptr);
return (new_ptr);
}