-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
42 lines (39 loc) · 1.41 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: ttavares <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/07 15:29:54 by ttavares #+# #+# */
/* Updated: 2022/11/21 16:42:14 by ttavares ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char*restrict dst, const char*restrict src, size_t dstsize)
{
size_t i;
size_t c;
size_t destlen;
size_t srclen;
i = 0;
c = 0;
if (!dst && dstsize == 0)
return (ft_strlen(src));
destlen = ft_strlen(dst);
srclen = ft_strlen(src);
if (dstsize == 0 || dstsize <= destlen)
return (dstsize + srclen);
if (!dst)
return (srclen);
while (dst[i] != '\0')
i++;
while (src[c] != '\0' && c < dstsize -1 - destlen)
{
dst[i] = src[c];
i++;
c++;
}
dst[i] = '\0';
return (destlen + srclen);
}