-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_realloc.c
More file actions
executable file
·34 lines (31 loc) · 1.31 KB
/
ft_realloc.c
File metadata and controls
executable file
·34 lines (31 loc) · 1.31 KB
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
34
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_realloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mberger <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/12/12 15:39:51 by mberger #+# #+# */
/* Updated: 2014/12/12 15:39:54 by mberger ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_realloc(void *ptr, size_t old, size_t size)
{
void *new;
if (ptr == NULL)
return (NULL);
if (size == 0)
new = (void *)ft_memalloc(sizeof(char));
else
new = (void *)ft_memalloc(size);
if (new == NULL)
return (NULL);
ft_bzero(new, (size) ? size : sizeof(char));
if (old > size)
ft_memcpy(new, ptr, (size) ? size : sizeof(char));
else
ft_memcpy(new, ptr, old);
ft_memdel((void *)&ptr);
return (new);
}