-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils_bonus.c
84 lines (73 loc) · 2.01 KB
/
get_next_line_utils_bonus.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
72
73
74
75
76
77
78
79
80
81
82
83
84
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kgriset <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/27 20:06:44 by kgriset #+# #+# */
/* Updated: 2023/11/27 20:23:41 by kgriset ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line_bonus.h"
size_t gnl_strlcpy(char *dst, const char *src, size_t dstsize)
{
size_t src_len;
size_t i;
src_len = dstsize;
i = 0;
if (!dstsize)
return (src_len);
while (dstsize && src[i])
{
dst[i] = src[i];
dstsize--;
i++;
}
return (src_len);
}
void free_t_buffer_chunk(t_buffer_chunk *first)
{
t_buffer_chunk *current;
t_buffer_chunk *next;
current = first;
while (current->next)
{
next = current->next;
free(current);
current = next;
}
free(current);
}
t_buff_ctrl add_back(t_buff_ctrl *buff_ctrl)
{
t_buffer_chunk *last;
last = malloc(sizeof(*last));
buff_ctrl->node->next = last;
buff_ctrl->node = last;
buff_ctrl->node_counter++;
if (!last)
return (*buff_ctrl);
last->next = NULL;
last->buff[0] = 0;
return (*buff_ctrl);
}
void init_t_buff_ctrl(t_buff_ctrl *buff_ctrl)
{
t_buffer_chunk *first_node;
first_node = malloc(sizeof(*first_node));
if (!first_node)
return ;
first_node->buff[0] = 0;
first_node->next = NULL;
buff_ctrl->first_node = first_node;
buff_ctrl->node_counter = 1;
}
size_t gnl_strlen(char *buffer)
{
size_t i;
i = 0;
while (buffer[i])
i++;
return (i);
}