-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcat.c
42 lines (38 loc) · 1.37 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: ael-khni <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/04 09:30:02 by ael-khni #+# #+# */
/* Updated: 2021/11/09 13:23:52 by ael-khni ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t ft_min(size_t x, size_t y)
{
if (x < y)
return (x);
return (y);
}
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t dst_len;
size_t src_len;
size_t i;
size_t result;
i = 0;
dst_len = ft_strlen(dst);
src_len = ft_strlen(src);
result = src_len + ft_min(dst_len, dstsize);
if (dstsize == 0)
return (result);
while (src[i] && dst_len + i < dstsize - 1)
{
dst[dst_len + i] = src[i];
i++;
}
dst[dst_len + i] = '\0';
return (result);
}