-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.c
70 lines (69 loc) · 1.32 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include<stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include<unistd.h>
#include<string.h>
#include <dirent.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<time.h>
#include<grp.h>
#include <sys/wait.h>
#include<fcntl.h>
#include "cd.h"
#include "command.h"
#include "display.h"
#include "echo.h"
#include "execute.h"
#include "ls.h"
#include "redirection.h"
#include "nightswatch.h"
#include "pinfo.h"
#include "pwd.h"
#include "global.h"
#include "global.c"
#include "env.h"
void ExecuteEnv(char *token, const char delemiter[] ,int flag)
{
char *argv[100];
int k;
int top = 0;
token = strtok(NULL, delemiter);
while(token != NULL)
{
argv[top++] = token;
token = strtok(NULL, delemiter);
}
if(flag == 1 && top >= 1 && top <= 2)
{
if(argv[1] != NULL)
{
k = setenv(argv[0],argv[1],1);
if(k < 0)
{
perror("unable to set the variable");
}
}
else
{
k = setenv(argv[0],"",1);
if(k < 0)
{
perror("unable to set the variable");
}
}
}
else if(top >= 1 && flag == 0)
{
k = unsetenv(argv[0]);
if(k < 0)
{
perror("unable to unset the variable");
}
}
else
{
fprintf(stderr,"Wrong usage of command\n");
}
return;
}