-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_strlcat.c
executable file
·42 lines (39 loc) · 1.33 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: jraymond <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/13 13:41:30 by jraymond #+# #+# */
/* Updated: 2017/11/16 16:34:09 by jraymond ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dest, const char *src, size_t size)
{
char *idest;
const char *isrc;
size_t n;
size_t idestlong;
idest = dest;
isrc = src;
n = size;
while (n-- != 0 && *idest != '\0')
idest++;
idestlong = idest - dest;
n = size - idestlong;
if (n == 0)
return (idestlong + ft_strlen(isrc));
while (*isrc)
{
if (n != 1)
{
*idest++ = *isrc;
n--;
}
isrc++;
}
*idest = '\0';
return (idestlong + (isrc - src));
}