-
Notifications
You must be signed in to change notification settings - Fork 1
/
set_unset_env.c
48 lines (46 loc) · 1014 Bytes
/
set_unset_env.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
#include "headers.h"
void set_env(char *token, int cnt)
{
char delim[] = " \n\t\r";
token = strtok(NULL, delim);
char *arg1 = (char*) malloc(sizeof(char) * MX_L1);
strcpy(arg1, token);
token = strtok(NULL, delim);
if (cnt == 1 || cnt > 3)
{
printf(DFLT "error: Incorrect number of arguments\n");
strcpy(emoji,":'(");
}
else
{
ll x;
if(cnt == 2)
x = setenv(arg1, "", 1);
else
x = setenv(arg1, token, 1);
if (x < 0)
{
perror(DFLT "error:\n");
strcpy(emoji,":'(");
}
}
}
void unset_env(char *token, int cnt)
{
char delim[] = " \n\t\r";
token = strtok(NULL, delim);
if (cnt != 2)
{
printf(DFLT "error: Incorrect number of arguments\n");
strcpy(emoji,":'(");
}
else
{
ll x = unsetenv(token);
if (x < 0)
{
perror(DFLT "error:\n");
strcpy(emoji,":'(");
}
}
}