-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcpy.c
48 lines (44 loc) · 1.57 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: kgajadie <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/11/17 16:36:31 by kgajadie #+# #+# */
/* Updated: 2020/11/17 16:41:11 by kgajadie ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Description:
** The strlcpy() function copies up to dstsize - 1 characters from the string
** src to dst, NUL-terminating the result if dstsize is not 0.
** Room for the NUL-terminator should be included in dstsize.
**
** Returns:
** total length of string it tries to create, aka length of src.
*/
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
{
unsigned long srclen;
size_t i;
if (!src || !dst)
return (0);
srclen = ft_strlen(src);
i = 0;
if (dstsize == 0)
return (srclen);
if (srclen == 0)
{
dst[0] = '\0';
return (srclen);
}
while ((src[i] != '\0') && (i < (dstsize - 1)))
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
return (srclen);
}