-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
38 lines (35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tedison <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/04/02 08:36:33 by tedison #+# #+# */
/* Updated: 2021/04/04 10:02:34 by tedison ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t i;
int src_i;
size_t size;
size_t size_src;
size_src = 0;
src_i = 0;
size = ft_strlen(dst);
i = ft_strlen(dst);
size_src = ft_strlen(src);
if (dstsize == 0)
return (size_src);
if (dstsize < size)
return (size_src + dstsize);
while (src[src_i] && (size + src_i) < dstsize)
dst[i++] = src[src_i++];
if ((size + src_i) == dstsize && dstsize > size)
dst[--i] = '\0';
else
dst[i] = '\0';
return (ft_strlen(src) + size);
}