-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.c
91 lines (82 loc) · 1.25 KB
/
print.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
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
#include "main.h"
/**
* _myenv - it prints environ
* @info: Struc
*
* Return: 0
*/
int _myenv(info_t *info)
{
print_list_str(info->env);
return (0);
}
/**
* _getenv - it gets the value
* @info: its Struc
* @name: name
*
* Return: value
*/
char *_getenv(info_t *info, const char *name)
{
list_t *node = info->env;
char *x;
while (node)
{
x = starts_with(node->str, name);
if (x && *x)
return (x);
node = node->next;
}
return (NULL);
}
/**
* _mysetenv - gives new environ
* @info: Struct
*
* Return: 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 - takeout envi var
* @info: Struc
*
* Return: 0
*/
int _myunsetenv(info_t *info)
{
int c;
if (info->argc == 1)
{
_eputs("Too few arguements.\n");
return (1);
}
for (c = 1; c <= info->argc; c++)
_unsetenv(info, info->argv[c]);
return (0);
}
/**
* populate_env_list - it populates env list
* @info: Struct
*
* Return: 0
*/
int populate_env_list(info_t *info)
{
list_t *node = NULL;
size_t c;
for (c = 0; environ[c]; c++)
add_node_end(&node, environ[c], 0);
info->env = node;
return (0);
}