-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_strlcat.c
More file actions
41 lines (37 loc) · 1.46 KB
/
ft_strlcat.c
File metadata and controls
41 lines (37 loc) · 1.46 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmoutaou <kmoutaou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/17 13:56:31 by kmoutaou #+# #+# */
/* Updated: 2021/11/23 16:17:42 by kmoutaou ### ########.fr */
/* */
/* ************************************************************************** */
/*
ft_strlcat is a re-coded strlcat function from <bsd/string.h> that
appends src onto the end of dest.
*/
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
unsigned int src_length;
unsigned int dst_length;
unsigned int i;
unsigned int j;
if (!dst || !src)
return (0);
src_length = ft_strlen(src);
dst_length = ft_strlen(dst);
if (size == 0)
return (src_length);
if (size <= dst_length)
return (size + src_length);
i = dst_length;
j = 0;
while (src[j] && i + 1 < size)
dst[i++] = src[j++];
dst[i] = '\0';
return (dst_length + src_length);
}