-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_exec.c
More file actions
51 lines (45 loc) · 923 Bytes
/
shell_exec.c
File metadata and controls
51 lines (45 loc) · 923 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
#include"shell.h"
/**
* shell_execute - executes the built in commands
* @argv: pointer to the argv
* @built_in_arr: pointer to the struct with built in comm
* Return: 1 on success
**/
int shell_execute(char **argv, built_in_t built_in_arr[])
{
int i = 0;
if (argv[0] == NULL)
return (0);
while (i < 5)
{
if (_strcmp(argv[0], built_in_arr[i].command) == 0)
{
return (built_in_arr[i].f(argv));
}
i++;
}
return (shell_launch(argv));
}
/**
* _freeall - frees arv and path
* @argv: Buffer containing the tokens
* @path: path to look for exec files
*/
void _freeall(char **argv, char **path)
{
free(argv[0]);
free(argv);
free(path);
}
/**
* check_existence - checkes whether a file exists
* @path: pointer to the path to search in
* Return: 1 on success, -1 if failed
*/
int check_existence(char *path)
{
int fd = access(path, F_OK | X_OK);
if (fd == -1)
return (-1);
return (1);
}