-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipex_exit.c
52 lines (48 loc) · 1.77 KB
/
pipex_exit.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_exit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bsyvasal <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/01 19:13:28 by bsyvasal #+# #+# */
/* Updated: 2024/02/20 10:58:51 by bsyvasal ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void clean_exit(t_pipe *data, char **arraylist, int exitno)
{
closepipe(data);
if (data->fd[0] > 2)
close(data->fd[0]);
if (data->fd[1] > 2)
close(data->fd[1]);
free(data->pid);
free(data->history_path);
freeall(data->cmds);
freeall(data->envp);
freeall(arraylist);
exit(exitno);
}
/**
* @brief Print error message and exits
* @brief Msg will be formatted: 'bvsh: @msg: @stderrmsg.
* @brief Exits if not set 0.
* @param msg and exits
* @param exit_status If set to -1 will get the errno.
*/
void errormsg_exit(char *msg, int exit_status, t_pipe *data)
{
if (exit_status == -1)
exit_status = errno;
ft_putstr_fd("bvsh: ", 2);
perror(msg);
clean_exit(data, NULL, exit_status);
}
void msg_freeall_exit(char *msg, char **arraylist, int exitno, t_pipe *data)
{
ft_putstr_fd("bvsh: ", 2);
ft_putstr_fd(msg, 2);
ft_putstr_fd("\n", 2);
clean_exit(data, arraylist, exitno);
}