42_minitalk/libftx/extra/ft_realloc.c
Camille Chauvet 9f50aaea4e normed
2023-01-24 16:15:20 +01:00

33 lines
1.2 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_realloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/05 18:58:48 by cchauvet #+# #+# */
/* Updated: 2023/01/20 16:22:50 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include "extra.h"
void *ft_realloc(void *tab, size_t size, size_t new_size, int bytes)
{
char *new;
size_t i;
new = ft_calloc(new_size, bytes);
if (new == NULL)
return (NULL);
i = 0;
while (i < size * bytes && tab != NULL)
{
new[i] = ((char *) tab)[i];
i++;
}
if (tab != NULL)
free(tab);
return (new);
}