-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenviron.c
More file actions
88 lines (79 loc) · 1.47 KB
/
environ.c
File metadata and controls
88 lines (79 loc) · 1.47 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "shell.h"
/**
* _myenv - displays current environ
* @info: contains potential arguments
* Return: Always 0
*/
int _myenv(info_t *info)
{
print_list_str(info->env);
return (0);
}
/**
* _getenv - gets the value variable
* @info: this is for potential arguments.
* @name: env var name
*
* Return: the value
*/
char *_getenv(info_t *info, const char *name)
{
list_t *node = info->env;
char *q;
while (node)
{
q = starts_with(node->str, name);
if (q && *q)
return (q);
node = node->next;
}
return (NULL);
}
/**
* _mysetenv - used to start new environment variable,
*
* @info: this struct containing potential arguments.
* Return: Always 0
*/
int _mysetenv(info_t *info)
{
if (info->argc != 3)
{
_eputs("Incorrect number of arguements\n");
return (1);
}
if (_setenv(info, info->argv[1], info->argv[2]))
return (0);
return (1);
}
/**
* _myunsetenv - this is to take out a variable
* @info: Used to maintainence of prototype.
* Return: Always 0
*/
int _myunsetenv(info_t *info)
{
int i;
if (info->argc == 1)
{
_eputs("Too few arguements.\n");
return (1);
}
for (i = 1; i <= info->argc; i++)
_unsetenv(info, info->argv[i]);
return (0);
}
/**
* populate_env_list - populates list
* @info: this is for good arguments
* Return: Always 0
*/
int populate_env_list(info_t *info)
{
list_t *node = NULL;
size_t i;
for (i = 0; environ[i]; i++)
add_node_end(&node, environ[i], 0);
info->env = node;
return (0);
}