-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.c
More file actions
47 lines (45 loc) · 1.12 KB
/
env.c
File metadata and controls
47 lines (45 loc) · 1.12 KB
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 "headers.h"
void set(char *commands[], ll n){
if(n == 1){
printf("\033[0;31mError: Too less arguments\033[0m\n");
return;
}
else if(n > 3){
printf("\033[0;31mError: Too many arguments\033[0m\n");
return;
}
else if(n == 2){
int x = setenv(commands[1], "\0", 1);
if(x == -1){
printf("\033[0;31mError: Unable to set\033[0m\n");
perror("setenv");
return;
}
}
else{
int x = setenv(commands[1], commands[2], 1);
if(x == -1){
printf("\033[0;31mError: Unable to set\033[0m\n");
perror("setenv");
return;
}
}
}
void unset(char *commands[], ll n){
if(n < 2){
printf("\033[0;31mError: Too less arguments\033[0m\n");
return;
}
else if(n > 2){
printf("\033[0;31mError: Too many arguments\033[0m\n");
return;
}
else {
int x = unsetenv(commands[1]);
if(x == -1){
printf("\033[0;31mError: Unable to unset\033[0m\n");
perror("unsetenv");
return;
}
}
}