-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnew_node_index.c
More file actions
68 lines (61 loc) · 1.74 KB
/
new_node_index.c
File metadata and controls
68 lines (61 loc) · 1.74 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* new_node_index.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mamoussa <mamoussa@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/28 16:56:04 by mamoussa #+# #+# */
/* Updated: 2020/12/10 16:43:41 by mamoussa ### ########.fr */
/* */
/* ************************************************************************** */
#include "shell.h"
t_pipe *new_node_index(size_t index)
{
t_pipe *new_node;
new_node = (t_pipe*)malloc(sizeof(t_pipe));
new_node->index = index;
new_node->fd0 = 0;
new_node->fd1 = 0;
new_node->next = NULL;
new_node->prev = NULL;
return (new_node);
}
void add_back(t_pipe *new_node)
{
t_pipe *current;
current = g_pipe_head;
if (!g_pipe_head)
{
g_pipe_head = new_node;
new_node->prev = g_pipe_head;
return ;
}
while (current)
{
if (!current->next)
{
current->next = new_node;
new_node->prev = current;
return ;
}
current = current->next;
}
}
void clear_list(void)
{
t_pipe *tmp;
if (!g_pipe_head)
return ;
while (g_pipe_head)
{
tmp = g_pipe_head->next;
if (g_pipe_head->fd0 > 2)
close(g_pipe_head->fd0);
if (g_pipe_head->fd1 > 2)
close(g_pipe_head->fd1);
free(g_pipe_head);
g_pipe_head = NULL;
g_pipe_head = tmp;
}
}