-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlcat.c
More file actions
33 lines (30 loc) · 1.35 KB
/
ft_strlcat.c
File metadata and controls
33 lines (30 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lilmende <lilmende@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 18:16:20 by lilmende #+# #+# */
/* Updated: 2023/11/02 13:08:08 by lilmende ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dst_len;
size_t src_len;
size_t remaining_space;
size_t to_copy;
dst_len = ft_strlen(dst);
src_len = ft_strlen(src);
if (dst_len >= size)
return (size + src_len);
remaining_space = size - dst_len - 1;
to_copy = src_len;
if (to_copy > remaining_space)
to_copy = remaining_space;
ft_memmove(dst + dst_len, src, to_copy);
dst[dst_len + to_copy] = '\0';
return (dst_len + src_len);
}