-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlcat.c
More file actions
45 lines (42 loc) · 1.65 KB
/
ft_strlcat.c
File metadata and controls
45 lines (42 loc) · 1.65 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jowagner <jowagner@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 14:02:38 by jowagner #+# #+# */
/* Updated: 2024/12/12 19:49:57 by jowagner ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/**
* @brief Appends src to dst, ensuring NULL-termination and
* not exceeding size bytes in dst.
*
* @param dst Pointer to the destination buffer.
* @param src Pointer to the source string to append.
* @param size Size of the destination buffer.
* @return The total length of the string it tried to create
* (initial length of dst plus length of src).
*/
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
size_t dest_len;
size_t src_len;
size_t i;
dest_len = 0;
while (dest_len < size && dest[dest_len])
dest_len++;
src_len = ft_strlen(src);
if (dest_len == size)
return (size + src_len);
i = 0;
while (dest_len + i + 1 < size && src[i])
{
dest[dest_len + i] = src[i];
i++;
}
dest[dest_len + i] = '\0';
return (dest_len + src_len);
}