-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathft_strlcat.c
30 lines (27 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ykoh <ykoh@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/03/17 22:37:45 by ykoh #+# #+# */
/* Updated: 2020/10/05 23:48:24 by ykoh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
const size_t srclen = ft_strlen(src);
const size_t dstlen = ft_strnlen(dst, dstsize);
if (dstsize == dstlen)
return (dstlen + srclen);
if (dstlen + srclen < dstsize)
ft_memcpy(dst + dstlen, src, srclen + 1);
else
{
ft_memcpy(dst + dstlen, src, dstsize - dstlen - 1);
dst[dstsize - 1] = '\0';
}
return (dstlen + srclen);
}