-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_realloc.c
33 lines (30 loc) · 1.18 KB
/
ft_realloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_realloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sebasnadu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/07 20:00:23 by sebasnadu #+# #+# */
/* Updated: 2024/02/07 20:14:12 by sebasnadu ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../include/libft.h"
void *ft_realloc(void *ptr, size_t size)
{
void *new;
if (!ptr)
return (ft_calloc(1, size));
if (!size && ptr)
{
ft_memclear(&ptr);
return (ptr);
}
new = malloc(size);
if (!new)
return (NULL);
ft_memcpy(new, ptr, size);
ft_memclear(&ptr);
ptr = new;
return (ptr);
}