-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcpy.c
68 lines (61 loc) · 1.62 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: masoares <masoares@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/02 20:47:51 by masoares #+# #+# */
/* Updated: 2023/10/08 13:36:47 by masoares ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t i;
char *c;
c = (char *) src;
i = 0;
if (ft_strlen(c) == 0)
{
dst[i] = '\0';
return (ft_strlen(c));
}
if (size > 0)
{
while (i <= ft_strlen(c) - 1)
{
if (i == size - 1)
break ;
dst[i] = c[i];
i++;
}
}
else
return (ft_strlen(c));
dst[i] = '\0';
return (ft_strlen(c));
}
/*
#include <stdio.h>
void test(int size)
{
char string[] = "Hello there, Venus";
char buffer[19];
int r;
r = ft_strlcpy(buffer,string,size);
printf("Copied '%s' into '%s', length %d\n",
string,
buffer,
r
);
}
int main()
{
test(19);
test(10);
test(1);
test(0);
return(0);
}
*/