-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcd.c
More file actions
36 lines (28 loc) · 633 Bytes
/
cd.c
File metadata and controls
36 lines (28 loc) · 633 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
35
36
#include "header.h"
ll CD(char **com)
{
if (com[1]== NULL)
{
fprintf(stderr,"No argument\n");
return 1;
}
char cwd[1024];
getcwd(cwd,sizeof(cwd));
if (strcmp(com[1],"-") == 0)
{
if (strcmp(lwd,"///")==0) return 0;
printf("%s\n",lwd);
if(chdir(actual_path(lwd))==-1)
perror("lwd error");
strcpy(lwd,relative_path(cwd));
return 0;
}
char *path = actual_path(com[1]);
if (chdir(path) == -1)
{
perror("CD error");
return 1;
}
strcpy(lwd,relative_path(cwd));
return 0;
}