-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
42 lines (38 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkahvedj <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/30 23:17:51 by jkahvedj #+# #+# */
/* Updated: 2021/06/12 20:12:17 by jkahvedj ### ########.fr */
/* */
/* ************************************************************************** */
/*
** LIBRARY: string.h
**
** DESCRIPTION:
** size-bounded string concatenation
*/
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t dstsize)
{
size_t dst_len;
size_t src_len;
size_t i;
dst_len = ft_strlen(dst);
src_len = ft_strlen(src);
if (dst_len >= dstsize)
return (src_len + dstsize);
i = 0;
while (dst[i] != '\0')
i++;
while (src[i - dst_len] != '\0' && i < (dstsize - 1))
{
dst[i] = src[i - dst_len];
i++;
}
dst[i] = '\0';
return (dst_len + src_len);
}