-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcpy.c
48 lines (44 loc) · 1.85 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lclerc <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/02 15:05:18 by lclerc #+# #+# */
/* Updated: 2022/11/23 16:22:23 by lclerc ### ########.fr */
/* */
/* ************************************************************************** */
/*
* strlcpy() and strlcat() copy and concatenate strings with the same input para
* meters and output result as snprintf(3)
*
* strlcpy() and strlcat() take the full size of the destination buffer and
* guarantee NUL termination, with the help of dstsize.
* - If the return value is >= dstsize, the output string has been truncated.
* - It is the caller's responsibility to handle this.
*
* strlcpy() copies up to dstsize - 1 characters from the string src to dst, NUL
* terminating the result if dstsize is not 0.
*
* If the src and dst strings overlap, the behavior is undefined.
* Improper use of the strncpy() and strncat() functions can result in buffer o
* verflow vulnerabilities.
* */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
size_t len;
size_t i;
i = 0;
len = ft_strlen(src);
if (dstsize == 0)
return (len);
while (i < dstsize - 1 && src[i] != '\0')
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (len);
}