-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strlcat.c
37 lines (34 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oadhesiv <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/04 19:38:06 by oadhesiv #+# #+# */
/* Updated: 2019/06/01 16:44:20 by oadhesiv ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dst_len;
size_t src_len;
size_t cpy_len;
if (!dst)
return (0);
dst_len = ft_strlen(dst);
src_len = ft_strlen(src);
if (dst_len >= size)
return (size + src_len);
dst += dst_len;
size -= dst_len;
if (src_len >= size)
cpy_len = size - 1;
else
cpy_len = src_len;
ft_memcpy(dst, src, cpy_len);
*(dst + cpy_len) = 0;
return (dst_len + src_len);
}