-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_parsing.c
More file actions
56 lines (51 loc) · 1.55 KB
/
ft_parsing.c
File metadata and controls
56 lines (51 loc) · 1.55 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parsing.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tarchimb <tarchimb@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/17 14:49:10 by tarchimb #+# #+# */
/* Updated: 2021/12/17 14:49:11 by tarchimb ### ########.fr */
/* */
/* ************************************************************************** */
#include "Includes/pipex.h"
char *ft_get_envp_path(char **envp, char *path)
{
int i;
i = 0;
while (envp[i])
{
path = ft_strnstr(envp[i],
"PATH=", ft_strlen(envp[i]));
if (path != NULL)
return (path);
i++;
}
return (NULL);
}
char **ft_parsing(char **envp)
{
char *envp_path;
char **paths;
char *tmp;
int i;
i = 0;
tmp = NULL;
envp_path = NULL;
envp_path = ft_get_envp_path(envp, envp_path);
if (!envp_path)
return (0);
envp_path = ft_substr(envp_path, 5, ft_strlen(envp_path) - 5);
paths = ft_split(envp_path, ':');
while (paths[i])
{
tmp = paths[i];
paths[i] = ft_strjoin(paths[i], "/");
free(tmp);
i++;
}
if (!paths)
return (0);
return (paths);
}