-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strlcat.c
executable file
·51 lines (47 loc) · 1.57 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mberger <mberger@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/11 17:21:11 by mberger #+# #+# */
/* Updated: 2014/11/11 17:21:27 by mberger ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_inc_counters(char **dest_copy, size_t *counter)
{
while (**dest_copy != '\0' && *counter != 0)
{
(*counter)--;
(*dest_copy)++;
}
}
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
char *dest_copy;
const char *src_copy;
size_t counter;
size_t dest_len;
dest_copy = dst;
src_copy = src;
counter = size;
ft_inc_counters(&dest_copy, &counter);
dest_len = dest_copy - dst;
counter = size - dest_len;
if (counter == 0)
return (ft_strlen(src_copy) + dest_len);
while (*src_copy != '\0')
{
if (counter != 1)
{
*dest_copy = *src_copy;
dest_copy++;
counter--;
}
src_copy++;
}
*dest_copy = '\0';
return ((src_copy - src) + dest_len);
}