diff options
Diffstat (limited to 'libft/src/ft_realloc.c')
-rw-r--r-- | libft/src/ft_realloc.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/libft/src/ft_realloc.c b/libft/src/ft_realloc.c new file mode 100644 index 0000000..34b43c3 --- /dev/null +++ b/libft/src/ft_realloc.c @@ -0,0 +1,26 @@ +#include <libft.h> +#include <stddef.h> +#include <stdlib.h> + +void + *ft_realloc(void *ptr, size_t size) +{ + void *nptr; + + if (!ptr) + { + if (!(ptr = malloc(size))) + return (NULL); + return (ptr); + } + else if (!size) + { + free(ptr); + return (NULL); + } + if (!(nptr = malloc(size))) + return (ptr); + ft_memcpy(nptr, ptr, ft_strlen(ptr)); + free(ptr); + return (nptr); +} |