-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexit.c
More file actions
41 lines (38 loc) · 949 Bytes
/
exit.c
File metadata and controls
41 lines (38 loc) · 949 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
#include "shell.h"
/**
* exit_func - exit function
* @shellf: shellf info including exit status
*
* Return: error no if fail
*/
int exit_func(shell_info __attribute__((unused)) shellf)
{
int stat;
char *loop;
loop = _itoa(shellf.loop_count);
if (shellf.args[1] != NULL)
{
stat = _atoi(shellf.args[1]);
if (stat < 0 || _strlen(shellf.args[1]) > 10)
{
write(STDERR_FILENO, shellf.name, _strlen(shellf.name));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, loop, _strlen(loop));
write(STDERR_FILENO, ": ", 2);
write(STDERR_FILENO, shellf.args[0], _strlen(shellf.args[0]));
write(STDERR_FILENO, ": Illegal number: ", 18);
write(STDERR_FILENO, shellf.args[1], _strlen(shellf.args[1]));
write(STDERR_FILENO, "\n", 1);
free(loop);
return (2);
}
if (stat >= 256)
shellf.stat = (stat % 256);
else
shellf.stat = stat;
}
free(loop);
freedom(shellf);
free_env(shellf);
exit(shellf.stat);
}