-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathft_strlcpy.c
53 lines (49 loc) · 2.13 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/30 21:33:05 by apuchill #+# #+# */
/* Updated: 2020/02/19 15:12:34 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: size-bounded string copying
**
** DESCRIPTION:
** The strlcpy() and strlcat() functions copy and concatenate strings
** respectively. They are designed to be safer, more consistent, and less
** error prone replacements for strncpy(3) and strncat(3). Unlike those
** functions, strlcpy() and strlcat() take the full size of the buffer (not
** just the length) and guarantee to NUL-terminate the result (as long as
** size is larger than 0 or, in the case of strlcat(), as long as there is
** at least one byte free in dst). Note that you should include a byte for
** the NUL in size. Also note that strlcpy() and strlcat() only operate on
** true ``C'' strings. This means that for strlcpy() src must be NUL-termi-
** nated and for strlcat() both src and dst must be NUL-terminated.
** The strlcpy() function copies up to size - 1 characters from the NUL-
** terminated string src to dst, NUL-terminating the result.
*/
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
size_t srcsize;
size_t i;
if (!dst || !src)
return (0);
srcsize = ft_strlen(src);
i = 0;
if (dstsize != 0)
{
while (src[i] != '\0' && i < (dstsize - 1))
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
}
return (srcsize);
}