-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
37 lines (33 loc) · 1.3 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ibeliaie <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/16 16:05:09 by ibeliaie #+# #+# */
/* Updated: 2023/05/18 17:22:18 by ibeliaie ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/* safely combine 2 strings, preventing buffer overflow */
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t i;
size_t j;
i = 0;
j = 0;
while (dst[i] && i < dstsize)
i++;
while (src[j] && (i + j + 1) < dstsize)
{
dst[i + j] = src[j];
j++;
}
if (i < dstsize)
dst[i + j] = '\0';
while (src[j])
j++;
return (i + j);
}
//as much of src is copied into dest as there is space for.