-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcpy.c
52 lines (44 loc) · 1.39 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 17:04:37 by tpouget #+# #+# */
/* Updated: 2020/05/14 17:06:12 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i;
i = 0;
if (size > 0)
{
while (src[i])
{
if (i + 1 == size)
break ;
dst[i] = src[i];
i++;
}
dst[i] = '\0';
}
return (ft_strlen(src));
}
/*
#include <unistd.h>
#include <stdio.h>
int main(int argc, char **argv)
{
if (argc != 2) return 0;
char buf[8] = "garbage";
int a = ft_strlcpy(buf, argv[1], sizeof buf);
if (a >= sizeof buf)
puts("Truncated\n");
else
puts("Not truncated\n")
write(1, buf, 8);
}
*/