aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-08-01 19:29:33 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-08-01 19:31:57 +0200
commitee32953ea79616e72f5428cdf40c834714a891c9 (patch)
treea2752a59225f06cb470ffde40c7bbe50a6f25a8d /src
parentca68aa1e6fca81213d19431439ad0b31863fe10c (diff)
downloadlibft-ee32953ea79616e72f5428cdf40c834714a891c9.tar.gz
libft-ee32953ea79616e72f5428cdf40c834714a891c9.tar.bz2
libft-ee32953ea79616e72f5428cdf40c834714a891c9.zip
Added ft_realloc, enabled ft_strnew
Diffstat (limited to 'src')
-rw-r--r--src/mem/ft_realloc.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mem/ft_realloc.c b/src/mem/ft_realloc.c
new file mode 100644
index 0000000..6047de8
--- /dev/null
+++ b/src/mem/ft_realloc.c
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_realloc.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/08/01 15:23:14 by charles #+# #+# */
+/* Updated: 2020/08/01 15:27:35 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_mem.h"
+
+/*
+** \brief Modified version of realloc function
+** \param ptr Pointer to re allocate
+** \param ptr_size Current allocated size
+** \param size New allocated size
+** \return New allocation or NULL on error
+*/
+
+void *ft_realloc(void *ptr, size_t ptr_size, size_t size)
+{
+ void *ret;
+
+ if ((ret = malloc(size)) == NULL)
+ {
+ free(ptr);
+ return (NULL);
+ }
+ if (ptr != NULL)
+ ft_memcpy(ret, ptr, ptr_size);
+ return (ret);
+}