-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
40 lines (37 loc) · 1.35 KB
/
ft_strlcat.c
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
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aldokezer <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/18 12:30:47 by orezek #+# #+# */
/* Updated: 2023/11/01 22:05:25 by aldokezer ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *to, const char *from, size_t size)
{
size_t src_len;
size_t dst_len;
size_t step;
src_len = ft_strlen(from);
dst_len = ft_strlen(to);
step = dst_len;
to += dst_len;
if (size <= dst_len)
return (src_len + size);
else if (src_len + dst_len >= size)
{
while (step++ < size - 1)
*(to++) = *(from++);
*to = '\0';
}
else
{
while (step++ < size && *from)
*(to++) = *(from++);
*to = '\0';
}
return (src_len + dst_len);
}