-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
42 lines (39 loc) · 1.27 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: msaliuta <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/27 18:57:46 by msaliuta #+# #+# */
/* Updated: 2018/11/04 14:25:33 by msaliuta ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
char *i;
char *j;
size_t k;
size_t dln;
i = (char*)dest;
j = (char*)src;
k = size;
while ((k-- != 0) && *i != '\0')
i++;
dln = i - dest;
k = size - dln;
if (k == 0)
return (dln + ft_strlen(j));
while (*j != '\0')
{
if (k != 1)
{
*i++ = *j;
k--;
}
j++;
}
*i = '\0';
return (dln + (j - src));
}