-
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.28 KB
/
ft_strlcat.c
File metadata and controls
42 lines (39 loc) · 1.28 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: ibohonos <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/25 10:54:51 by ibohonos #+# #+# */
/* Updated: 2017/11/06 18:02:10 by ibohonos ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
char *nd;
const char *ns;
size_t i;
size_t dlen;
nd = dest;
ns = src;
i = size;
while (i-- != 0 && *nd != '\0')
nd++;
dlen = nd - dest;
i = size - dlen;
if (i == 0)
return (dlen + ft_strlen(ns));
while (*ns != '\0')
{
if (i != 1)
{
*nd++ = *ns;
i--;
}
ns++;
}
*nd = '\0';
return (dlen + (ns - src));
}