-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.c
84 lines (69 loc) · 1.25 KB
/
environment.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdlib.h>
#include <pwd.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include "parse.h"
#include "main.h"
void func_set(char * input)
{
char * value;
int chk;
chk =0;
int chk1 = 0;
char * var;
char * temp = malloc (1 + strlen(input));
strcpy(temp,input);
input = strtok(NULL, " \t\r\n");
if(input == NULL)
{
printf("setenv has 0 arguments. Not valid\n");
return;
}
var = input;
input = strtok(NULL, " \t\r\n");
if(input != NULL)
{
value = input;
chk = 1;
}
if(input != NULL)
{
input = strtok(NULL, " \t\n\r");
if(input != NULL)
chk1 = 1;
}
if(chk1 == 1)
{
printf("setenv has more than 2 arguments. Not valid\n");
}
if(chk == 1 && chk1 == 0)
{
printf("%s\n",var);
printf("%s\n",value);
setenv(var, value, 1);
}
else
setenv(var, "", 1);
return;
}
void func_unset(char * input)
{
char * var;
char * temp = malloc (1 + strlen(input));
strcpy(temp,input);
input = strtok(NULL, " \t\r\n");
if(input == NULL)
{
printf("wrong usage of unsetenv. Not valid\n");
return;
}
var = input;
unsetenv(var);
return;
}