-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
41 lines (38 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbari <mbari@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/19 16:31:49 by mbari #+# #+# */
/* Updated: 2021/06/01 17:43:21 by mbari ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
size_t ldst;
size_t lsrc;
size_t cut;
size_t res;
cut = 0;
lsrc = ft_strlen(src);
if (!dst && !size)
return (lsrc);
ldst = ft_strlen(dst);
if (size > ldst)
{
cut = size - ldst - 1;
res = ldst + lsrc;
}
else
res = lsrc + size;
i = 0;
while (i < cut && src[i])
dst[ldst++] = src[i++];
if (cut)
dst[ldst] = '\0';
return (res);
}