This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_strlcat.c
49 lines (43 loc) · 1.69 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcombeau <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/24 15:14:19 by mcombeau #+# #+# */
/* Updated: 2021/12/02 16:13:28 by mcombeau ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
DESCRIPTION :
The function ft_strlcat appends the given string src to the end of
dst. It will append at most dstsize - ft_strlen(dst) - 1 and
nul-terminate the result.
Note : space for the terminating \0 character must be included in dstsize.
RETURN VALUE :
The total length of the string that it tried to create : the initial
length of dst + the length of src, with the goal to facilitate
truncaction detection.
*/
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t i;
size_t j;
size_t d_size;
size_t s_size;
d_size = ft_strlen(dst);
s_size = ft_strlen(src);
if (dstsize <= d_size)
return (dstsize + s_size);
i = d_size;
j = 0;
while ((i + j) < (dstsize - 1) && src[j] != '\0')
{
dst[i + j] = src[j];
j++;
}
dst[i + j] = '\0';
return (d_size + s_size);
}