-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_strlcat.c
39 lines (35 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tsomsa <tsomsa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/02/22 17:31:51 by tsomsa #+# #+# */
/* Updated: 2022/02/22 17:31:53 by tsomsa ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void my_cp(char *d, const char *s, size_t n);
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
size_t srclen;
size_t destlen;
srclen = ft_strlen(src);
destlen = ft_strlen(dest);
if (destlen >= size)
return (size + srclen);
if (srclen + destlen < size)
my_cp(dest + destlen, src, srclen + 1);
else
{
my_cp(dest + destlen, src, size - 1);
dest[size - 1] = '\0';
}
return (srclen + destlen);
}
static void my_cp(char *d, const char *s, size_t n)
{
while (n-- > 0)
*d++ = *s++;
}