-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strjoin_old.c
More file actions
33 lines (31 loc) · 1.28 KB
/
ft_strjoin_old.c
File metadata and controls
33 lines (31 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acastrov <acastrov@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/23 21:16:07 by acastrov #+# #+# */
/* Updated: 2024/09/28 19:54:19 by acastrov ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// Calculates size, allocates memory and cat 2 strings via strlcpy
char *ft_strjoin(char const *s1, char const *s2)
{
char *ts;
size_t tl;
size_t sl1;
size_t sl2;
if (!s1 || !s2)
return (NULL);
sl1 = ft_strlen(s1);
sl2 = ft_strlen(s2);
tl = sl1 + sl2 + 1;
ts = malloc(tl);
if (!ts)
return (NULL);
ft_strlcpy(ts, s1, sl1 + 1);
ft_strlcpy((ts + sl1), s2, sl2 + 1);
return (ts);
}