-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcpy.c
54 lines (45 loc) · 1.5 KB
/
ft_strlcpy.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
53
54
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: julmuntz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/10 11:30:37 by julmuntz #+# #+# */
/* Updated: 2022/05/19 16:21:24 by julmuntz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i[2];
i[0] = 0;
i[1] = 0;
while (src[i[1]])
i[1]++;
if (size <= 0)
return (i[1]);
while (src[i[0]] && i[0] < size - 1)
{
dst[i[0]] = src[i[0]];
i[0]++;
}
dst[i[0]] = 0;
return (i[1]);
}
/*
#include <stdio.h>
#include <bsd/string.h>
int main(void)
{
char src[100] = "Hello";
char dst[100];
puts("\n- strlcpy");
printf("%lu\n", strlcpy(dst, src, 5));
printf("%s\n", dst);
puts("\n- ft_strlcpy");
printf("%lu\n", ft_strlcpy(dst, src, 5));
printf("%s\n", dst);
return 0;
}
*/