aboutsummaryrefslogtreecommitdiff
path: root/src/dstr
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-09 17:57:10 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-09 17:57:10 +0200
commit6fe30c97aad7a4a3564e7037d64a43edcb9a2162 (patch)
tree5d36f19eb619811c93b852c5f5e04eb6fe12e85c /src/dstr
parentf1babc364b2507cb8999d3132941b056feac37cd (diff)
downloadlibft-6fe30c97aad7a4a3564e7037d64a43edcb9a2162.tar.gz
libft-6fe30c97aad7a4a3564e7037d64a43edcb9a2162.tar.bz2
libft-6fe30c97aad7a4a3564e7037d64a43edcb9a2162.zip
Added ft_dstrwrap, ft_splitf, fixing bug in ft_split
Diffstat (limited to 'src/dstr')
-rw-r--r--src/dstr/ft_dstrnew.c14
-rw-r--r--src/dstr/ft_dstrwrap.c25
2 files changed, 32 insertions, 7 deletions
diff --git a/src/dstr/ft_dstrnew.c b/src/dstr/ft_dstrnew.c
index 8ae4a64..fe9ce46 100644
--- a/src/dstr/ft_dstrnew.c
+++ b/src/dstr/ft_dstrnew.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/03 13:54:52 by charles #+# #+# */
-/* Updated: 2020/04/04 19:50:38 by charles ### ########.fr */
+/* Updated: 2020/06/09 17:35:14 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,12 +21,12 @@
t_ftdstr *ft_dstrnew(char *from)
{
- t_ftdstr *dstr;
+ char *clone;
+ t_ftdstr *ret;
- if ((dstr = (t_ftdstr*)malloc(sizeof(t_ftdstr))) == NULL ||
- (dstr->str = ft_strdup(from)) == NULL)
+ if ((clone = ft_strdup(from)) == NULL)
return (NULL);
- dstr->length = ft_strlen(from);
- dstr->capacity = dstr->length + 1;
- return (dstr);
+ if ((ret = ft_dstrwrap(clone)) == NULL)
+ free(clone);
+ return (ret);
}
diff --git a/src/dstr/ft_dstrwrap.c b/src/dstr/ft_dstrwrap.c
new file mode 100644
index 0000000..0acf684
--- /dev/null
+++ b/src/dstr/ft_dstrwrap.c
@@ -0,0 +1,25 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_dstrwrap.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/06/09 17:32:30 by charles #+# #+# */
+/* Updated: 2020/06/09 17:33:57 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft_dstr.h"
+
+t_ftdstr *ft_dstrwrap(char *str)
+{
+ t_ftdstr *dstr;
+
+ if ((dstr = (t_ftdstr*)malloc(sizeof(t_ftdstr))) == NULL)
+ return (NULL);
+ dstr->str = str;
+ dstr->length = ft_strlen(str);
+ dstr->capacity = dstr->length + 1;
+ return (dstr);
+}