-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfree_error.c
More file actions
66 lines (58 loc) · 1.79 KB
/
free_error.c
File metadata and controls
66 lines (58 loc) · 1.79 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* free_error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sanmetol <sanmetol@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/26 19:39:06 by sanmetol #+# #+# */
/* Updated: 2024/11/26 22:26:50 by sanmetol ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
void close_pipes(t_pipex *pipex)
{
int i;
i = 0;
while (i < pipex->cmd_count - 1)
{
close(pipex->pipes[i][0]);
close(pipex->pipes[i][1]);
i++;
}
}
void cleanup(t_pipex *pipex)
{
int i;
close_pipes(pipex);
close(pipex->infile);
close(pipex->outfile);
if (pipex->here_doc)
unlink("/tmp/heredoc_pipex");
i = 0;
while (pipex->cmd_paths && pipex->cmd_paths[i])
free(pipex->cmd_paths[i++]);
free(pipex->cmd_paths);
i = 0;
while (i < pipex->cmd_count - 1)
free(pipex->pipes[i++]);
free(pipex->pipes);
}
void free_cmd_args(char **cmd_args)
{
int i;
i = 0;
while (cmd_args[i])
free(cmd_args[i++]);
free(cmd_args);
}
void handle_error(char errType, const char *msg, int exit_code)
{
//fprintf(stderr, "Mensaje de depuración, error: %d\n msg: %s\n", exit_code, msg);
if (errType == 'p')
perror(msg);
else
ft_putstr_fd(msg, STDERR_FILENO);
if (exit_code != -1)
exit(exit_code);
}