-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuiltin_functions.c
62 lines (56 loc) · 1.06 KB
/
builtin_functions.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
53
54
55
56
57
58
59
60
61
62
#include "shell.h"
/**
*env - prints the current_environnement
*@tokenized_command: command entered
*
*Return: void
*/
void env(char **tokenized_command __attribute__((unused)))
{
int i;
for (i = 0; environ[i] != NULL; i++)
{
print(environ[i], STDOUT_FILENO);
print("\n", STDOUT_FILENO);
}
}
/**
* quit - exits the shell
* @tokenized_command: command entered
*
* Return: void
*/
void quit(char **tokenized_command)
{
int num_token = 0, arg;
for (; tokenized_command[num_token] != NULL; num_token++)
;
if (num_token == 1)
{
free(tokenized_command);
free(line);
free(commands);
exit(status);
}
else if (num_token == 2)
{
arg = _atoi(tokenized_command[1]);
if (arg == -1)
{
print(shell_name, STDERR_FILENO);
print(": 1: exit: Illegal number: ", STDERR_FILENO);
print(tokenized_command[1], STDERR_FILENO);
print("\n", STDERR_FILENO);
status = 2;
}
else
{
free(line);
free(tokenized_command);
free(commands);
exit(arg);
}
}
else
print("$: exit doesn't take more than one argument\n", STDERR_FILENO);
}