-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSS_environ.c
More file actions
100 lines (85 loc) · 1.95 KB
/
SS_environ.c
File metadata and controls
100 lines (85 loc) · 1.95 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
89
90
91
92
93
94
95
96
97
98
99
#include "shell.h"
/**
* _myenv - this function print the current environment
* @info: function parameter indicating struct containing potential argument
* Return: 0 if sucessfully
*/
int _myenv(info_t *info)
{
print_list_str(info->env);
return (0);
}
/**
* _getenv - function returns the value of an environment variable by it name
* @info: function parameter indicating structure containing potential argument
* @name: function parameter indicating the name of the environment variable
* Return: the value of the environment
*/
char *_getenv(info_t *info, const char *name)
{
list_t *node = info->env;
char *b;
while (node)
{
b = starts_with(node->str, name);
if (b && *b)
return (b);
node = node->next;
}
return (NULL);
}
/**
* _mysetenv - this function is use to create a new variable or
* to modify an existing one
* @info: function parameter indicating a struct containing potential arguments
* Return: 0 if successful
*/
int _mysetenv(info_t *info)
{
if (info->argc != 3)
{
_eputs("Incorrect number of arguments\n");
return (1);
}
if (setenv(info->argv[1], info->argv[2], 1) == -1)
return (0);
return (1);
}
/**
* _myunsetenv - this function is responsible for removing one or more
* environment variable
* @info: function parameter indicating struct containing potential argument
* Return: 0 if successful
*/
int _myunsetenv(info_t *info)
{
int a;
if (info->argc == 1)
{
_eputs("Too few arguments.\n");
return (1);
}
for (a = 1; a < info->argc; a++)
{
if (unsetenv(info->argv[a]) == -1)
{
perror("unsetenv");
return (1);
}
}
return (0);
}
/**
* populate_env_list - this function is use to populate the list of env variabl
* @info: function parameter of a structure containing potential argument
* Return: 0 if successfully
*/
int populate_env_list(info_t *info)
{
size_t a;
list_t *node = NULL;
for (a = 0; environ[a]; a++)
add_node_end(&node, environ[a], 0);
info->env = node;
return (0);
}