-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
42 lines (39 loc) · 1.33 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: pablomar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/08 17:50:54 by pablomar #+# #+# */
/* Updated: 2019/11/16 20:45:19 by pablomar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
char *pdst;
const char *psrc;
size_t n;
size_t dstlen;
pdst = dst;
psrc = src;
n = dstsize;
while (*pdst != '\0' && n-- != 0)
pdst++;
dstlen = pdst - dst;
n = dstsize - dstlen;
if (n == 0)
return (dstlen + ft_strlen(src));
while (*psrc != '\0')
{
if (n != 1)
{
*pdst++ = *psrc;
n--;
}
psrc++;
}
*pdst = '\0';
return (dstlen + (psrc - src));
}