-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_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: ftonita <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/02 00:13:04 by ftonita #+# #+# */
/* Updated: 2021/11/02 00:13:05 by ftonita ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
char *d;
const char *s;
size_t n;
size_t dl;
n = dstsize;
s = src;
d = dst;
while (n-- != 0 && *d != '\0')
d++;
dl = d - dst;
n = dstsize - dl;
if (n == 0)
return (dl + ft_strlen (s));
while (*s != '\0')
{
if (n != 1)
{
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return (dl + (s - src));
}