From 87b90103930d83d74baa998866b0995cb8887d51 Mon Sep 17 00:00:00 2001 From: Christopher Uhlig Date: Sat, 25 Jan 2025 13:01:10 +0100 Subject: fixed leaks in tokenizer and collectargs also fixed seg for < > and improved value add by $ use --- lib/libft/ft_strjoin.c | 56 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'lib/libft/ft_strjoin.c') diff --git a/lib/libft/ft_strjoin.c b/lib/libft/ft_strjoin.c index 5c0bf41..2cf68ea 100644 --- a/lib/libft/ft_strjoin.c +++ b/lib/libft/ft_strjoin.c @@ -6,41 +6,41 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/07 10:15:33 by dkaiser #+# #+# */ -/* Updated: 2025/01/22 00:27:04 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 12:55:14 by chuhlig ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -// static int copy_str(char *dst, const char *src) -// { -// int i; - -// i = 0; -// while (src[i]) -// { -// dst[i] = src[i]; -// i++; -// } -// return (i); -// } +static int copy_str(char *dst, const char *src) +{ + int i; + + i = 0; + while (src[i]) + { + dst[i] = src[i]; + i++; + } + return (i); +} -char *ft_strjoin(const char *s1, const char *s2) +char *ft_strjoin(char const *s1, char const *s2) { - char *joined_str; - size_t len1; - size_t len2; - - if (!s1 || !s2) - return (NULL); - len1 = strlen(s1); - len2 = strlen(s2); - joined_str = malloc(len1 + len2 + 1); - if (!joined_str) - return (NULL); - strcpy(joined_str, s1); - strcat(joined_str, s2); - return (joined_str); + int len; + char *result; + + len = ft_strlen(s1) + ft_strlen(s2); + result = malloc(len + 1); + if (result) + { + result[len] = '\0'; + len = copy_str(result, s1); + len = copy_str(result + len, s2); + return (result); + } + else + return (0); } /* #include */ -- cgit v1.2.3