-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcd.h
More file actions
34 lines (33 loc) · 661 Bytes
/
cd.h
File metadata and controls
34 lines (33 loc) · 661 Bytes
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
#ifndef za
#define za
int implement_cd(){
char ch[100]={'\0'};
char save[1024];
save[1023] = '\0';
strcpy(ch,input[1]);
if(!strlen(ch)){
if(chdir(cwd) < 0)
perror("cd failed");
return 1;
} else if(ch[0] == '~'){
strcpy(save,cwd);
strcat(save,"/");
strcat(save,ch+1);
if(chdir(save) < 0)
perror("cd failed");
return 1;
}
if(ch[0]!='/'){
getcwd(save,sizeof(save));
strcat(save,"/");
strcat(save,ch);
if(chdir(save) < 0)
perror("cd failed");
return 1;
} else {
if(chdir(ch) < 0)
perror("cd failed");
return 1;
}
}
#endif