-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange_directory.c
66 lines (66 loc) · 1.24 KB
/
change_directory.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
#include "change_directory.h"
void change_directory()
{
char lt[1024]={};
char gt[1024]={};
int flag0=0;
int flag1=0;
int flag2=0;
int l=i;
int out=0;
int in=0;
/* while(arg[l][0]!=';')
{
if(arg[l][0]=='<' && arg[l][1]!='<' && flag0==0)
{
flag0=1;
strcpy(lt,arg[l+1]);
l++;
}
else if(arg[l][0]=='>'&&arg[l][1]!='>')
{
// out = open(arg[l+1],O_WRONLY|O_CREAT,0644);
flag1++;
strcpy(gt,arg[l+1]);
l++;
}
else if(arg[l][0]=='>'&&arg[l][1]=='>')
{
flag2++;
strcpy(gt,arg[l+1]);
l++;
}
l++;
}
printf("%d %d %d %s %s\n",flag0,flag1,flag2,lt,gt);
*/
if(strcmp(arg[i+1],"~")==0)
chdir(pr_dir);
else if(chdir(arg[i+1])==0)
getcwd(pwd, sizeof(pwd));
else
printf(RED "Error:Enter valid directory" RESET "\n");
i+=2;
return;
}
void gen_cd_child()
{
if(strcmp(arg[i+1],"~")==0)
{
chdir(pr_dir);
printf(RESET "cd with pid %d exited normally\n" RESET,getpid() );
}
else if(chdir(arg[i+1])==0)
{
getcwd(pwd, sizeof(pwd));
printf(RESET "cd with pid %d exited normally\n" RESET,getpid() );
}
else
{
printf(RED "Error:Enter valid directory" RESET "\n");
}
i+=2;
kill(getpid(),SIGKILL);
ampcount--;
exit(0);
}