aboutsummaryrefslogtreecommitdiffstats
path: root/libft/src/ft_nrealloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'libft/src/ft_nrealloc.c')
-rw-r--r--libft/src/ft_nrealloc.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/libft/src/ft_nrealloc.c b/libft/src/ft_nrealloc.c
new file mode 100644
index 0000000..96d5ad1
--- /dev/null
+++ b/libft/src/ft_nrealloc.c
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* LE - / */
+/* / */
+/* ft_nrealloc.c .:: .:/ . .:: */
+/* +:+:+ +: +: +:+:+ */
+/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
+/* #+# #+ #+ #+# */
+/* Created: 2020/01/09 15:58:24 by rbousset #+# ## ## #+# */
+/* Updated: 2020/01/09 15:58:25 by rbousset ### #+. /#+ ###.fr */
+/* / */
+/* / */
+/* ************************************************************************** */
+
+#include <libft.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+void
+ *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize)
+{
+ void *nptr;
+
+ if (!ptr)
+ {
+ if (!(ptr = malloc(newsize)))
+ return (NULL);
+ return (ptr);
+ }
+ else if (!newsize)
+ {
+ free(ptr);
+ return (NULL);
+ }
+ if (!(nptr = malloc(newsize)))
+ return (ptr);
+ ft_memcpy(nptr, ptr, oldsize);
+ free(ptr);
+ return (nptr);
+}