-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
95 lines (85 loc) · 1.89 KB
/
get_next_line_utils.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
85
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: joandre- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/17 00:05:06 by joandre- #+# #+# */
/* Updated: 2024/10/15 15:49:35 by joandre- ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void *clean_buffer(size_t len)
{
char *buffer;
if (!len)
return (NULL);
buffer = malloc(len);
if (!buffer)
return (NULL);
while (len--)
buffer[len] = '\0';
return (buffer);
}
bool is_newline(t_line *lst)
{
size_t i;
while (lst)
{
i = 0;
while (lst->buff[i])
if (lst->buff[i++] == '\n')
return (true);
lst = lst->next;
}
return (false);
}
size_t get_line_size(t_line *lst)
{
size_t len;
size_t i;
len = 0;
while (lst)
{
i = 0;
while (lst->buff[i])
{
if (lst->buff[i++] == '\n')
return (len + 1);
++len;
}
lst = lst->next;
}
return (len);
}
void copy_line(t_line *lst, char *line)
{
size_t i;
size_t k;
if (!lst || !line)
return ;
k = 0;
while (lst)
{
i = 0;
while (lst->buff[i])
{
if (lst->buff[i] == '\n')
{
line[k] = lst->buff[i];
return ;
}
line[k++] = lst->buff[i++];
}
lst = lst->next;
}
}
t_line *last_node(t_line *lst)
{
if (!lst)
return (NULL);
while (lst->next)
lst = lst->next;
return (lst);
}