This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_strlcpy.c
43 lines (37 loc) · 1.54 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/24 14:16:24 by mcombeau #+# #+# */
/* Updated: 2021/12/03 16:32:30 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
DESCRIPTION :
The function ft_strlcpy copies up to size - 1 characters from the given
string src to the given string dst, nul-terminating the result.
Note : space for the terminating \0 character must be included in dstsize.
RETURN VALUE :
The total length of the string that it tried to create : the length of
src, with the goal to facilitate truncaction detection.
*/
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
size_t i;
size_t srclen;
srclen = ft_strlen(src);
if (dstsize == 0)
return (srclen);
i = 0;
while (i < (dstsize - 1) && src[i] != '\0')
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (srclen);
}