forked from AingeruAlvarezSanchez/Libft
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_strlcat.c
43 lines (40 loc) · 1.6 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aalvarez <aalvarez@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/16 22:45:01 by aalvarez #+# #+# */
/* Updated: 2022/08/17 20:25:08 by aalvarez ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief appends the string pointed by src to the string pointed by dst.
*
* @param dst the string to be appended.
* @param src the string to append.
* @param dstsize the size of dst.
* @return size_t the len of the string that strlcat tried to create.
*/
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t i;
size_t j;
size_t dstlen;
if (dstsize == 0)
return (ft_strlen(src));
if (dstsize < ft_strlen(dst))
return (ft_strlen(src) + dstsize);
j = 0;
dstlen = ft_strlen(dst);
i = ft_strlen(dst);
while (src[j] && (dstlen + j) < dstsize)
dst[i++] = src[j++];
if ((dstlen + j) == dstsize && dstlen < dstsize)
dst[i - 1] = 0;
else
dst[i] = 0;
return (ft_strlen(src) + dstlen);
}