-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell_exit.c
41 lines (39 loc) · 752 Bytes
/
shell_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
#include "shell.h"
/**
* shell_exit - function to handle exit command
*
* @args: input argument
* Return: as need
*/
int shell_exit(char **args)
{
int i, status;
char *nl;
const char *err_msg;
if (args[1] != NULL)
{
if (_strcmp(args[1], "HBTN") == 0)
{
err_msg = "Invalid argument";
write(STDERR_FILENO, err_msg, _strlen(err_msg));
nl = "\n";
write(STDERR_FILENO, nl, 1);
return (EXIT_FAILURE);
}
for (i = 0; args[1][i] != '\0'; i++)
{
if (!_isdigit(args[1][i]))
{
err_msg = "Invalid arguments\n";
write(STDERR_FILENO, args[1], _strlen(args[1]));
nl = "\n";
write(STDERR_FILENO, nl, 1);
return (EXIT_FAILURE);
}
}
status = _atoi(args[1]);
return (status);
}
else
return (0);
}