-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.c
More file actions
55 lines (49 loc) · 963 Bytes
/
env.c
File metadata and controls
55 lines (49 loc) · 963 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
#include "header.h"
// setenv <var> [value]
// includes <var> in env variables with [value](if no value given then empty string)
ll SENV(char **com)
{
ll len = 0, ret = 0;
while (com[len]!=NULL)
len++;
if (len==2)
{
if (setenv(com[1],"",1)<0)
{
fprintf(stderr,"setenv error");
ret=1;
}
}
else if (len==3)
{
if (setenv(com[1],com[2],1)<0)
{
fprintf(stderr,"setenv error");
ret=1;
}
}
else
{
fprintf(stderr,"Error: setenv <var> [value]\n");
ret=1;
}
return ret;
}
// removes env variable from the env
ll UNSENV(char **com)
{
ll len = 0;
while (com[len]!=NULL)
len++;
if (len!=2)
{
fprintf(stderr,"unsetenv <var>\n");
return 1;
}
if (unsetenv(com[1])<0)
{
fprintf(stderr,"unsetenv error\n");
return 1;
}
return 0;
}