-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvcmd.c
56 lines (52 loc) · 987 Bytes
/
envcmd.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
#include "prototype.h"
extern struct utsname UNAME;
extern char* SYSTEM_NAME;
extern char HOME[500005];
extern char* USER;
extern char PWD_ABS_NAME[500005];
extern char PWD_NAME[500005];
extern DIR* PWD;
extern char* cmd;
extern int num_built_in;
extern char children_name[100000][51];
extern pid_t bg_children_PIDs[1000];
extern int bg_num_children;
extern pid_t currentChildPID;
extern pid_t startShellPID;
extern volatile sig_atomic_t run_clock;
void setEnv(int argc, char* argv[])
{
int ret = 0;
if(argc != 3)
{
fprintf(stderr, "Error: Invalid usage of setenv\n");
return;
}
else
{
ret = setenv(argv[1], argv[2], 1);
if(ret != 0)
{
perror("setenv");
return;
}
}
}
void unsetEnv(int argc, char* argv[])
{
int ret = 0;
if(argc != 2)
{
fprintf(stderr, "Error: Invalid usage of unsetenv\n");
return;
}
else
{
ret = unsetenv(argv[1]);
if(ret != 0)
{
perror("unsetenv");
return;
}
}
}