-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtokenizeEnvVar.c
46 lines (40 loc) · 879 Bytes
/
tokenizeEnvVar.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
#include "shell.h"
/**
* tokenizeEnvVar - tokenize specified env variable
* @var: environmental variable
* Return: array of tokenized strings
*/
char **tokenizeEnvVar(char *var)
{
char **tokes;
char *var_str;
int len;
var_str = _getenv(var);
len = _strlen(var_str);
tokes = createTokes(var_str, len, ":");
return (tokes);
}
/**
* _getenv - searches the environment list (array of strings) to find the
* environment variable name and returns a pointer to the corresponding value
* @name: for our purposes will be "PATH"
* Return: pointer to the value string
*/
char *_getenv(const char *name)
{
char const *name_cpy;
char **cpy = environ;
while (*cpy != NULL)
{
name_cpy = name;
while (**cpy == *name_cpy)
name_cpy++, (*cpy)++;
if (*name_cpy == '\0' && **cpy == '=')
{
(*cpy) -= 4;
return ((*cpy) + 5);
}
cpy++;
}
return (NULL);
}