-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcpy.c
49 lines (45 loc) · 1.59 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edboutil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/12 09:46:18 by edboutil #+# #+# */
/* Updated: 2022/11/22 12:27:19 by edboutil ### ########lyon.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: size-bounded string copying and concatenation
**
** DESCRIPTION:
** The strlcpy() and strlcat() functions copy and concatenate strings with the
** same input parameters and output result as snprintf(3). They are designed to
** be safer, more consistent, and less error prone replacements for the easily
** misused functions strncpy(3) and strncat(3).
*/
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
size_t i;
size_t len;
i = 0;
len = 0;
if (!dst || !src)
return (0);
if (dstsize > 0)
{
while (src[i] != '\0' && i < dstsize - 1)
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
}
while (src[len] != '\0')
{
len++;
}
return (len);
}