-
Notifications
You must be signed in to change notification settings - Fork 1
/
child_process.c
75 lines (64 loc) · 1.48 KB
/
child_process.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
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "shell.h"
/**
* null_command - Free the buffer created
*@buffer: buffer taked from getline
*Return: Nothing(void)
*/
void null_command(char *buffer)
{
free(buffer);
exit(EXIT_SUCCESS);
}
/**
* get_out - Free the buffer and commands taken from getline
*@buffer: buffer taked from getline
*@commands: command inserted
*Return: Nothing(void)
*/
void get_out(char *buffer, char **commands)
{
free(buffer);
free_all_dp(commands);
exit(EXIT_SUCCESS);
}
/**
* env_end - Function to frees the buffer and commands created in getline
*@buffer: buffer from getline
*@commands: array store commands
*@env: enviroment variables
*Return: Nothing(void)
*/
void env_end(char *buffer, char **commands, char **env)
{
free(buffer);
free_all_dp(commands);
print_env(env);
exit(EXIT_SUCCESS);
}
/**
* _path - Function to check and execute the command inserted
*@commands: array sotored commands
*@buffer: buffer from getline
*@env: enviroment variables
*@argv: argument vector
*@count: number of times runned the prompt
*/
void _path(char **commands, char *buffer, char **env, char **argv, int count)
{
struct stat fileStat2;
int i = 0;
char **directories;
directories = store_e_variables(commands[0], env);
while (directories[i])
{
if (stat(directories[i], &fileStat2) == 0)
execve(directories[i], commands, NULL);
i++;
}
/*if command not found print error*/
build_message(argv, commands[0], count);
free(buffer);
free_all_dp(commands);
free_all_dp(directories);
exit(EXIT_SUCCESS);
}