-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexiting_shell.c
More file actions
39 lines (37 loc) · 795 Bytes
/
exiting_shell.c
File metadata and controls
39 lines (37 loc) · 795 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
#include "simple_shell.h"
/**
* exit_shell - executes the exit command
* @arr: an array of command inputs
* @l: input from the user
* @new_l: user's input having newline trunc
* @cmd_num: counts the number of commands entered
* Return: 0 (success), exit code
*/
int exit_shell(char **arr, char *l, char *new_l, int cmd_num)
{
int n, k = 0;
char *cmdcount;
if (arr[1] == NULL)
{
free_everything(l, new_l, arr);
exit(2);
}
else
{
n = atois(arr[1]);
if (n == -1)
{
cmdcount = _printint(cmd_num);
write(STDERR_FILENO, arr[0], 7);
write(STDERR_FILENO, cmdcount, str_len(cmdcount));
write(STDERR_FILENO, ": exit: cmd not found!: ", 24);
while (arr[1][k] != '\0')
k++;
write(STDOUT_FILENO, arr[1], k);
write(STDOUT_FILENO, "\n", 1);
return (0);
}
free_everything(l, new_l, arr);
_exit(n);
}
}