-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecve.c
More file actions
53 lines (50 loc) · 962 Bytes
/
execve.c
File metadata and controls
53 lines (50 loc) · 962 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
#include "shell.h"
/**
* _execev - Execute a programming exec
* @line: recieved from strtok the token
* @argv: line of arguments of file
* @num: variablei internal
* @isatty_val: is the tty
* @envi: enviroment variable
* Return: None
*/
void _execev(char **line, char *argv, int num, int isatty_val, char **envi)
{
pid_t pid;
int _exec = 0;
if (line[0] == NULL)
return;
if (is_buit(line, envi) == 1)
return;
pid = fork();
if (pid < 0)
{
printf("Error during fork\n");
free_dp(line);
exit(EXIT_FAILURE);
}
else if (pid != 0)
{
wait(NULL);
return;
}
else
{
if (check_path(envi, line) == 0)
_exec = execve(line[0], line, NULL);
if (_exec < 0)
{
if (isatty_val == 1)
{
printf("%s: No such file or directory\n", argv);
free(line);
exit(EXIT_SUCCESS);
}
printf("%s: %d: %s: not found\n", argv, num, line[0]);
free(line);
exit(EXIT_FAILURE);
}
free_dp(line);
exit(EXIT_SUCCESS);
}
}