-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
52 lines (41 loc) · 1.6 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
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julmuntz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/10 12:46:16 by julmuntz #+# #+# */
/* Updated: 2022/05/20 17:12:00 by julmuntz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t ft_strnlen(const char *str, size_t maxlen)
{
const char *ptr = str;
while (maxlen-- > 0 && *ptr)
ptr++;
return (ptr - str);
}
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t len;
len = ft_strnlen(dst, size);
if (len == size)
return (len + ft_strlen(src));
return (len + ft_strlcpy(dst + len, src, size - len));
}
/*
#include <stdio.h>
#include <bsd/string.h>
int main(void)
{
char dst[100] = "Qwertyuiop";
char src[100] = "Asdfghj";
puts("\n- strlcat");
printf("Size of Dest + Srce = %lu\n", strlcat(dst, src, 5));
puts("\n- ft_strlcat");
printf("Size of Dest + Srce = %lu\n", ft_strlcat(dst, src, 5));
return 0;
}
*/