-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit_paths.c
76 lines (68 loc) · 1.78 KB
/
split_paths.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
76
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* split_paths.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdiouf <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/10/10 19:01:21 by mdiouf #+# #+# */
/* Updated: 2014/11/01 15:10:33 by mdiouf ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_minishell1.h"
int test_for_path(char *str)
{
if (str[0] == 'P' && str[1] == 'A' && str[2] == 'T' &&
str[3] == 'H' && str[4] == '=')
return (1);
else
return (0);
}
void cpy_path(char **cpy_path, char **env)
{
int i;
i = 0;
while (env[i] != '\0')
{
if (test_for_path(env[i]))
{
*cpy_path = ft_strdup(env[i]);
break ;
}
i++;
}
}
void rmv_path(char **path)
{
int i;
i = 5;
while ((*path)[i] != '\0')
{
(*path)[i - 5] = (*path)[i];
(*path)[i] = '\0';
i++;
}
}
char **ft_split_path(char **envp, char ***env)
{
int i;
char *path;
char **split_path;
i = 0;
path = NULL;
while (envp[i] != '\0')
i++;
*env = (char**)malloc(sizeof(char*) * (i + 1));
i = 0;
while (envp[i] != '\0')
{
(*env)[i] = ft_strdup(envp[i]);
i++;
}
(*env)[i] = NULL;
i = 0;
cpy_path(&path, *env);
rmv_path(&path);
split_path = ft_strsplit(path, ':');
return (split_path);
}