diff options
-rw-r--r-- | libft/src/ft_split.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/libft/src/ft_split.c b/libft/src/ft_split.c index 1d33dda..5a7bf2d 100644 --- a/libft/src/ft_split.c +++ b/libft/src/ft_split.c @@ -1,10 +1,23 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_split.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2020/02/02 17:07:16 by rbousset #+# ## ## #+# */ +/* Updated: 2020/02/02 17:07:17 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + #include <libft.h> #include <stddef.h> #include <stdlib.h> #include <inttypes.h> static size_t -ft_count_words(const char *s, char c) + ft_count_words(const char *s, char c) { size_t i; size_t count; @@ -30,7 +43,7 @@ ft_count_words(const char *s, char c) } static size_t -ft_splitlen(const char *str, char c) + ft_splitlen(const char *str, char c) { size_t i; @@ -58,15 +71,16 @@ static char return (word); } -static void -ft_splitfree(char **best_split, size_t j) +static char + **ft_splitfree(char **best_split, size_t j) { while (j > 0) { - free(best_split[j]); + ft_memdel((void**)&best_split[j]); j--; } - free(best_split); + ft_memdel((void**)best_split); + return (NULL); } char @@ -88,10 +102,7 @@ char while (s[i] != c && s[i]) { if (!(best_split[j] = ft_splitdup(s + i, c))) - { - ft_splitfree(best_split, j); - return (NULL); - } + return (ft_splitfree(best_split, j)); i += ft_splitlen(s + i, c); j++; } |