-
Notifications
You must be signed in to change notification settings - Fork 0
/
vec_strlcat.c
71 lines (65 loc) · 1.7 KB
/
vec_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vec_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: toramo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/02 10:49:48 by toramo #+# #+# */
/* Updated: 2024/01/02 10:49:49 by toramo ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t vec_strlen(const char *str)
{
int n;
n = 0;
if (str[0] != 0)
{
while (str[n] != 0)
{
n++;
}
}
return (n);
}
static size_t ft_vec_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
size_t j;
i = 0;
while (i < size && *dst)
{
dst++;
i++;
}
if (i == size)
return (i + vec_strlen((char *)src));
j = 0;
while (src[j])
{
if (j < size - i - 1)
*dst++ = src[j];
j++;
}
*dst = 0;
return (j + i);
}
int vec_strlcat(t_vec *dst, char *src, size_t l)
{
if (!dst)
return (-1);
if (!dst->memory)
if (vec_new(dst, l, 1) < 0)
return (-1);
if (dst->elem_size != 1)
return (-1);
if (l + dst->len < dst->alloc_size)
{
if (vec_resize(dst, l + dst->len) <= 0)
return (-1);
}
ft_vec_strlcat((char *)dst->memory, src, l);
dst->len += l;
return (dst->len);
}