-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
executable file
·47 lines (43 loc) · 1.39 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mwilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/08 16:13:48 by mwilliam #+# #+# */
/* Updated: 2016/12/10 13:20:25 by mwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Copies and appends the NULL-terminated string src to dst
** and returns the total length of the string
*/
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
char *dst2;
char *src2;
size_t dst_len;
dst2 = dst;
src2 = (char *)src;
while (*dst2 && size)
{
dst2++;
size--;
}
dst_len = dst2 - dst;
if (size == 0)
return (dst_len + ft_strlen(src));
while (*src2)
{
if (size > 1)
{
*dst2++ = *src2;
size--;
}
src2++;
}
*dst2 = '\0';
return (dst_len + (src2 - src));
}