/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_nrealloc.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:06:43 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:06:43 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include void *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize) { void *nptr; if (ptr == NULL) { if ((ptr = malloc(newsize)) == NULL) return (NULL); return (ptr); } else if (!newsize) { ft_memdel((void*)&ptr); return (NULL); } if ((nptr = malloc(newsize)) == NULL) return (ptr); ft_memcpy(nptr, ptr, oldsize); ft_memdel((void*)&ptr); return (nptr); }