-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mskeleto <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 13:12:43 by mskeleto #+# #+# */
/* Updated: 2020/11/09 19:52:09 by mskeleto ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dest, const char *src, size_t dstsize)
{
int i;
size_t k;
size_t j;
i = 0;
j = 0;
k = 0;
if (dstsize <= ft_strlen(dest))
return (ft_strlen(src) + dstsize);
while (dest[j] != '\0')
j++;
k = j;
while ((src[i] != '\0') && (j < dstsize - 1))
{
dest[j] = src[i];
i++;
j++;
}
dest[j] = '\0';
if (src[i] == '\0')
return (j);
while (src[i] != '\0')
i++;
return ((size_t)(k + i));
}