-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
57 lines (52 loc) · 1.84 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anamart3 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/29 19:09:49 by anamart3 #+# #+# */
/* Updated: 2023/05/10 20:03:41 by anamart3 ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t get_result_length(size_t dst_l, size_t dstsize, size_t src_l)
{
if (dst_l > dstsize)
return (src_l + dstsize);
return (dst_l + src_l);
}
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t initial_dst_length;
size_t src_length;
size_t i_dst;
size_t i_src;
initial_dst_length = ft_strlen(dst);
src_length = ft_strlen(src);
i_dst = initial_dst_length;
i_src = 0;
if (dstsize <= initial_dst_length)
return (src_length + dstsize);
if (dstsize != 0)
{
while (src[i_src] && i_dst < dstsize - 1)
{
dst[i_dst] = src[i_src];
i_dst++;
i_src++;
}
dst[i_dst] = '\0';
}
return (get_result_length(initial_dst_length, dstsize, src_length));
}
// #include <stdio.h>
// int main(void)
// {
// char dst1[] = "123456789";
// char src[] = "ana";
// size_t total_length = 0;
// printf("My function return: %lu\n", ft_strlcat(dst1, NULL, total_length));
// printf("My function dst: %s\n", dst1);
// return (0);
// }