-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlcat.c
More file actions
42 lines (39 loc) · 1.52 KB
/
ft_strlcat.c
File metadata and controls
42 lines (39 loc) · 1.52 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: moabed <moabed@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/08/07 21:26:20 by moabed #+# #+# */
/* Updated: 2025/08/19 18:00:37 by moabed ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t dstsize;
size_t srcsize;
size_t i;
srcsize = ft_strlen(src);
dstsize = ft_strlen(dst);
if (size == 0)
return (srcsize);
if (dstsize >= size)
return (size + srcsize);
i = 0;
while (src[i] && (dstsize + i) < (size - 1))
{
dst[dstsize + i] = src[i];
i++;
}
dst[dstsize + i] = '\0';
return (dstsize + srcsize);
}
/*
size is the expected size of the dst we have sent , in reality ,
if its lower or equal than dstsize
(dstsize > size) we should return the expected string (srclen +size) but,
if its higher than the dst size
just return the (dstsize + srcsize)
*/