-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_exit_shell.c
More file actions
42 lines (37 loc) · 823 Bytes
/
_exit_shell.c
File metadata and controls
42 lines (37 loc) · 823 Bytes
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
#include "shell.h"
/**
* _exit_shell - terminate the shell
* @args: a list of arguments to exit as well as the 'exit' as first element
*
* Description: Usage -- exit [status]
* Return: Success if all was processed fine, else Failure
*/
pid_t _exit_shell(const char **args)
{
int status = 0, i = 0;
const int EXIT_DEFAULT = 2;
if (args == NULL || args[0] == NULL)
{
return (SHELL.BUILTIN_FAILURE);
}
errno = SHELL.END_SHELL;
if (args[1] == NULL)
{
return (SHELL.BUILTIN_SUCCESS);
}
for (i = 0; args[1][i] != '\0'; i++)
{
if (isalpha(args[1][i]))
status = -1;
else
status = atoi(args[1]);
}
if (status < 0)
{
fprintf(stderr, "%s: 1: exit: Illegal number: %s\n",
ERR_PROMPT, args[1]);
status = EXIT_DEFAULT;
}
SHELL.LAST_EXIT_STATUS = status;
return (SHELL.BUILTIN_SUCCESS);
}