-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlcat.c
More file actions
49 lines (46 loc) · 1.78 KB
/
Copy pathft_strlcat.c
File metadata and controls
49 lines (46 loc) · 1.78 KB
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: maaugust <maaugust@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/09 18:09:05 by maaugust #+# #+# */
/* Updated: 2026/03/19 15:41:07 by maaugust ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @fn size_t ft_strlcat(char *dst, const char *src, size_t size)
* @brief Size-bounded string concatenation.
* @details Appends string src to the end of dst. It will append at most
* size - strlen(dst) - 1 characters. It will then NUL-terminate, unless
* size is 0 or the original dst string was longer than size.
* @param dst Destination buffer.
* @param src Source string.
* @param size Size of the destination buffer.
* @return The total length of the string it tried to create.
*/
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dst_len;
size_t src_len;
size_t i;
size_t j;
src_len = ft_strlen(src);
if (!dst && size == 0)
return (src_len);
dst_len = ft_strlen(dst);
if (size <= dst_len)
return (size + src_len);
i = dst_len;
j = 0;
while (src[j] && (i + 1) < size)
{
dst[i] = src[j];
i++;
j++;
}
dst[i] = '\0';
return (dst_len + src_len);
}