-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
57 lines (52 loc) · 1.56 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edboutil <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/12 09:53:40 by edboutil #+# #+# */
/* Updated: 2022/11/17 20:13:37 by edboutil ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strncat(char *dest, const char *src, size_t nb)
{
int i;
unsigned int j;
i = 0;
j = 0;
while (dest[i])
{
i++;
}
while (src[j] && j < nb)
{
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}
size_t ft_strlcat(char *dest, const char *src, size_t dstsize)
{
unsigned int dest_size;
unsigned int src_size;
dest_size = ft_strlen(dest);
src_size = ft_strlen(src);
if (dstsize <= dest_size)
{
return (dstsize + src_size);
}
else if (dstsize <= dest_size + src_size)
{
ft_strncat(dest, src, dstsize - dest_size - 1);
return (dest_size + src_size);
}
else
{
ft_strncat(dest, src, src_size);
return (dest_size + src_size);
}
}