-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfree_error.c
More file actions
98 lines (90 loc) · 2.28 KB
/
free_error.c
File metadata and controls
98 lines (90 loc) · 2.28 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
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
96
97
98
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: marvin <marvin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/16 13:44:05 by marvin #+# #+# */
/* Updated: 2024/01/16 13:44:05 by marvin ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
void free_all_possible_path(t_data *data)
{
int i;
i = 0;
while (data->all_paths[i])
{
free(data->all_paths[i]);
i++;
}
free(data->all_paths);
}
void free_cmd_path(t_data *data)
{
int i;
int j;
i = 0;
while (i < data->argc - 3)
{
j = 0;
while (data->cmd[i][j])
{
free(data->cmd[i][j]);
j++;
}
free(data->cmd[i]);
i++;
}
free(data->cmd);
i = 0;
while (i < data->argc - 3)
{
free(data->path[i]);
i++;
}
free(data->path);
}
void perror_child(int i, t_data *data)
{
if (i == 1)
perror("pipe");
else if (i == 2)
perror("fork");
else if (i == 3 || i == 13)
perror("dup2 stdout");
else if (i == 4 || i == 14)
perror("execve");
else if (i == 5 || i == 8 || i == 12)
perror("dup2 stdin child");
else if (i == 6)
perror("pipe heredoc");
else if (i == 7)
perror("fork heredoc");
else if (i == 9 || i == 10)
perror("argc too few arguments");
else if (i == 11)
perror("open file");
else if (i == 15)
perror("malloc path");
free_cmd_path(data);
free_all_possible_path(data);
exit (1);
}
void perror_dup_files(int i)
{
if (i == 1)
perror("argc too few arguments");
else if (i == 2)
perror("open file");
else if (i == 3)
perror("dup2 file stdin");
exit (1);
}
void free_heredoc(t_data *data)
{
free(data->line);
free(data->returnline);
exit (0);
}