-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipex_parsing.c
52 lines (47 loc) · 1.58 KB
/
pipex_parsing.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pipex_parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jimchoi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/17 15:49:31 by jimchoi #+# #+# */
/* Updated: 2024/05/02 20:20:33 by jimchoi ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipex.h"
char **get_path(char **envp)
{
int i;
char **path;
i = 0;
while (envp[i] != NULL)
{
if (ft_strncmp(envp[i], "PATH=", 5) == 0)
{
envp[i] += 5;
path = ft_split(envp[i], ':');
return (path);
}
i++;
}
path = ft_split("/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin:.", ':');
return (path);
}
char *path_check(t_data *path_data, char *cmd)
{
int i;
i = 0;
if (cmd == NULL)
handle_exit("command not found", 127);
cmd = ft_strjoin("/", cmd);
while (path_data->path[i] != NULL)
{
path_data->cmd_path = ft_strjoin(path_data->path[i], cmd);
if (access(path_data->cmd_path, X_OK) == 0)
return (path_data->cmd_path);
i++;
}
handle_exit("command not found", 127);
return (0);
}