summaryrefslogtreecommitdiffstats
path: root/libft/src/ft_strjoin.c
diff options
context:
space:
mode:
Diffstat (limited to 'libft/src/ft_strjoin.c')
-rw-r--r--libft/src/ft_strjoin.c42
1 files changed, 9 insertions, 33 deletions
diff --git a/libft/src/ft_strjoin.c b/libft/src/ft_strjoin.c
index f666781..2e00daf 100644
--- a/libft/src/ft_strjoin.c
+++ b/libft/src/ft_strjoin.c
@@ -11,32 +11,7 @@
/* / */
/* ************************************************************************** */
-#include "libft.h"
-#include <stdlib.h>
-
-size_t
- ft_strleen(const char *s)
-{
- size_t i;
-
- i = 0;
- while (s[i] != '\0')
- i++;
- return (i);
-}
-
-static char
- *ft_recalloc(size_t size)
-{
- char *str;
-
- str = 0;
- str = malloc((size + 1) * sizeof(char));
- if (!str)
- return (NULL);
- ft_bzero(str, size);
- return (str);
-}
+#include <libft.h>
char
*ft_strjoin(const char *s1, const char *s2)
@@ -44,20 +19,21 @@ char
char *str;
size_t i;
size_t j;
- size_t size;
+ size_t len;
- size = (ft_strleen(s1) + ft_strleen(s2));
- str = (char*)ft_recalloc(ft_strleen(s1) + ft_strleen(s2));
+ if (!s1 || !s2)
+ return (NULL);
+ len = ft_strlen(s1) + ft_strlen(s2);
+ if (!(str = ft_nstr(len)))
+ return (NULL);
i = 0;
j = 0;
- if (!str)
- return (NULL);
- while (i < ft_strleen(s1))
+ while (s1[i] != '\0')
{
str[i] = s1[i];
i++;
}
- while (i < size)
+ while (s2[j] != '\0')
{
str[i] = s2[j];
i++;