-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_var.c
53 lines (49 loc) · 1.02 KB
/
env_var.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
#include"headerfiles/headers.h"
#include"headerfiles/env_var.h"
void setenv_func(char arg[]){
if(strcmp(arg, "setenv")==0){
printf("Invalid number of arguments passed\n");
return;
}
char var[40], val[256];
char *token = strtok(arg, " ");
token = strtok(NULL, " ");
strcpy(var, token);
token = strtok(NULL, " ");
if(token!=NULL){
strcpy(val, token);
token = strtok(NULL, " ");
}
else{
val[0] = '\0';
}
if(token!=NULL){
printf("Invalid number of arguments passed\n");
return;
}
int x = setenv(var, val, 1);
if(x<0){
printf("Error number %d\n", errno);
perror("Setenv:");
}
}
void unsetenv_func(char arg[]){
if(strcmp(arg, "unsetenv")==0){
printf("Invalid number of arguments passed\n");
return;
}
char var[40];
char *token = strtok(arg, " ");
token = strtok(NULL, " ");
strcpy(var, token);
token = strtok(NULL, " ");
if(token!=NULL){
printf("Invalid number of arguments passed");
return;
}
int x = unsetenv(var);
if(x<0){
printf("Error number %d\n", errno);
perror("Unsetenv:");
}
}