forked from yazgiraldoa/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtins.c
49 lines (41 loc) · 783 Bytes
/
builtins.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
#include "shell.h"
/**
* get_builtin - Function that look for a builtin (env, exit, etc).
* @string: string to be evaluated as builtin.
* Return: A function associated with the builtin name (success).
*/
int (*get_builtin(char *string))()
{
unsigned int j = 0;
while (list[j].name != NULL)
{
if ((_strcmp(string, list[j].name)) == 0)
{
return (list[j].func);
}
j++;
}
return (NULL);
}
/**
* env - function that prints environment variables.
* Return: Success is 0
*/
int env(void)
{
int i = 0;
for (i = 0; environ[i]; i++)
{
write(1, environ[i], _strlen(environ[i]));
write(1, "\n", 1);
}
return (0);
}
/**
* _own_exit - function that exit the terminal.
* Return: 1 as a flag to return in main function.
*/
int _own_exit(void)
{
return (1);
}