-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_env.c
More file actions
63 lines (55 loc) · 886 Bytes
/
get_env.c
File metadata and controls
63 lines (55 loc) · 886 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
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
#include "shell.h"
/**
* print_env - prints
* @s: string
* @env: environment
* Return: (0)
*/
int print_env(char **s, list_t *env)
{
sh_free_double_ptr(s);
print_list(env);
return (0);
}
/**
* h_getenv - get environment variables
* @s: string
* @env: environment
* Return: environment variable
*/
char *h_getenv(char *s, list_t **env)
{
int en = 0;
int vars = 0;
while (*env != NULL)
{
en = 0;
while ((*env)->var[en] == s[en])
en++;
if (s[en] == '\0' && ((*env)->var[en] == '='))
break;
*env = (*env)->next;
}
while (s[vars] != '\0')
vars++;
vars++;
return (env_strdup((*env)->var, vars));
}
/**
* list_env - linked list calls variables
* @env: variable
*
* Return: list
*/
list_t *list_env(char **env)
{
list_t *head;
int en = 0;
head = NULL;
while (env[en] != NULL)
{
add_node_end(&head, env[en]);
en++;
}
return (head);
}