-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__setenv.c
More file actions
48 lines (45 loc) · 695 Bytes
/
__setenv.c
File metadata and controls
48 lines (45 loc) · 695 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
#include "builtins.h"
/**
* __setenv - sets the environment variables
* @info: arguments passed
*
* Return: status
*/
int __setenv(info_t *info)
{
env_t *var;
char **args = info->tokens + 1, *val;
if (args[0])
{
if (args[1])
{
if (args[2])
{
perrorl("Too many arguments.", *info->tokens, NULL);
info->status = EXIT_FAILURE;
return (info->status);
}
val = args[1];
}
else
{
val = "";
}
var = get_dict_node(info->env, args[0]);
if (var)
{
free(var->val);
var->val = _strdup(val);
}
else
{
add_dict_node_end(&info->env, args[0], val);
}
info->status = EXIT_SUCCESS;
}
else
{
__env(info);
}
return (info->status);
}