-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexit_status.c
52 lines (44 loc) · 1.62 KB
/
exit_status.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exit_status.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaesjeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/11 20:34:06 by jaesjeon #+# #+# */
/* Updated: 2022/09/22 17:00:17 by minsuki2 ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell_info.h"
#include "ft_command.h"
static int *_get_address_exit_status(void)
{
static int exit_status;
return (&exit_status);
}
void set_exit_status(int status)
{
int *exit_status;
exit_status = _get_address_exit_status();
*exit_status = status;
return ;
}
int get_exit_status(void)
{
int *exit_status;
exit_status = _get_address_exit_status();
return (*exit_status);
}
int get_exit_code(int status)
{
if (WIFEXITED(status))
return (WEXITSTATUS(status));
else if (WIFSIGNALED(status))
return (WTERMSIG(status) + SIG_DEFAULT_EXIT_CODE);
else if (WIFSTOPPED(status))
return (SIGSTOP + SIG_DEFAULT_EXIT_CODE);
else if (WIFCONTINUED(status))
return (SIGCONT + SIG_DEFAULT_EXIT_CODE);
else
return (GENERAL_EXIT_CODE);
}