-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathft_strlcat.c
52 lines (48 loc) · 2.2 KB
/
ft_strlcat.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuchill <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/12/04 21:44:39 by apuchill #+# #+# */
/* Updated: 2020/02/19 15:12:28 by apuchill ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: <string.h>
** SYNOPSIS: size-bounded string concatenation
**
** 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 strlcat() function appends the NUL-terminated string src to the end
** of dst. It will append at most size - strlen(dst) - 1 bytes, NUL-termi
** nating the result.
*/
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t c;
size_t d;
if (dstsize <= ft_strlen(dst))
return (dstsize + ft_strlen(src));
c = ft_strlen(dst);
d = 0;
while (src[d] != '\0' && c + 1 < dstsize)
{
dst[c] = src[d];
c++;
d++;
}
dst[c] = '\0';
return (ft_strlen(dst) + ft_strlen(&src[d]));
}