2023-01-23 07:22:30 -05:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* 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)
|
|
|
|
{
|
2023-01-24 10:15:20 -05:00
|
|
|
char *new;
|
2023-01-23 07:22:30 -05:00
|
|
|
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++;
|
|
|
|
}
|
2023-01-23 08:13:48 -05:00
|
|
|
if (tab != NULL)
|
|
|
|
free(tab);
|
2023-01-23 07:22:30 -05:00
|
|
|
return (new);
|
|
|
|
}
|