forked from thecamo1509/simple_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathl_path.c
More file actions
37 lines (36 loc) · 693 Bytes
/
l_path.c
File metadata and controls
37 lines (36 loc) · 693 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
#include "functions.h"
/**
* l_path - Function to check if the value is in the PATH
* @cont: The char previously read by the input
* @env: The environ
* Return: A concatenated string with the new path or cont if it fails
*/
char *l_path(char *cont, char **env)
{
char *value;
char *car = "/";
char *newpath = NULL;
char **token = NULL;
int compare = 1;
int i = 0;
value = _getenv("PATH", env);
token = words(value, ":");
while (token[i])
{
newpath = str_concat(token[i], car, cont);
compare = access(newpath, X_OK);
if (compare == 0)
{
return (newpath);
/*free(newpath);*/
break;
}
else
{
free(newpath);
i++;
}
}
free(token);
return (cont);
}