-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcat.c
35 lines (32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mfebvay <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2013/11/20 19:37:26 by mfebvay #+# #+# */
/* Updated: 2015/01/23 01:50:03 by mfebvay ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dst_len;
size_t cpy_len;
size_t src_len;
dst_len = 0;
while (dst[dst_len])
dst_len++;
src_len = 0;
while (src[src_len])
src_len++;
if (size <= dst_len)
return (src_len + size);
if ((cpy_len = size - dst_len - 1) > src_len)
cpy_len = src_len;
dst[dst_len + cpy_len] = 0;
while (cpy_len--)
dst[dst_len + cpy_len] = src[cpy_len];
return (dst_len + src_len);
}