-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin.c
More file actions
55 lines (49 loc) · 811 Bytes
/
builtin.c
File metadata and controls
55 lines (49 loc) · 811 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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "shell.h"
/**
* check_exit - handles the exit builtin
* @command: command entered
* @buffer: input buffer
* @stat: exit status
*/
void check_exit(char **command, char *buffer, int *stat)
{
int status;
char *exit_command = "exit";
if (strcmp(command[0], exit_command) == 0)
{
if (command[1] == NULL)
{
free(buffer);
free_arr(command);
exit(*stat);
}
else
{
status = atoi(command[1]);
free(buffer);
free_arr(command);
exit(status);
}
}
}
/**
* check_env - handles the env builtin
* @command: command entered
* Return: 0 or 1
*/
int check_env(char *command)
{
int i = 0;
char *env = "env";
if (strcmp(command, env) == 0)
{
while (environ[i] != NULL)
{
printf("%s\n", environ[i]);
i++;
}
free(command);
return (0);
}
return (1);
}