-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_next_line_utils.c
68 lines (63 loc) · 1.77 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_next_line_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: coskelet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/16 19:21:36 by coskelet #+# #+# */
/* Updated: 2021/12/02 17:48:36 by coskelet ### ########.fr */
/* */
/* ************************************************************************** */
#include "get_next_line.h"
void get_list_elem(const int fd, t_list **lst, t_list **l_elem)
{
t_list *prev;
prev = NULL;
*l_elem = *lst;
while (*l_elem && (*l_elem)->fd != fd)
{
prev = *l_elem;
*l_elem = (*l_elem)->next;
}
if (*l_elem && (*l_elem)->fd == fd)
return ;
*l_elem = (t_list *)malloc(sizeof(t_list));
if (!(*l_elem))
return ;
(*l_elem)->fd = fd;
(*l_elem)->next = NULL;
(*l_elem)->buf_line = NULL;
(*l_elem)->buf_line_size = 0;
if (prev)
prev->next = *l_elem;
else
*lst = *l_elem;
return ;
}
void free_list(t_list **lst, int fd)
{
t_list *prev;
t_list *cur;
prev = *lst;
cur = *lst;
while (cur)
{
if (cur->fd == fd)
{
if (cur->buf_line)
free(cur->buf_line);
if (prev == cur && !cur->next)
*lst = NULL;
else if (prev == cur)
*lst = cur->next;
else
prev->next = NULL;
free(cur);
return ;
}
prev = cur;
cur = cur->next;
}
return ;
}