-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
42 lines (39 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmachado <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/06 21:25:20 by gmachado #+# #+# */
/* Updated: 2022/04/13 19:58:32 by gmachado ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
const char *src_start;
const char *dst_start;
size_t dst_length;
src_start = src;
dst_start = dst;
while (size != 0 && *dst != '\0')
{
dst++;
size--;
}
dst_length = dst - dst_start;
if (size == 0)
return (ft_strlen(src) + dst_length);
while (*src != '\0')
{
if (size != 1)
{
*dst++ = *src;
size--;
}
src++;
}
*dst = '\0';
return (dst_length + src - src_start);
}