-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcd.c
52 lines (44 loc) · 836 Bytes
/
cd.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
#include "cd.h"
#include "prompt.h"
#include "headers.h"
#include "cwd.h"
void cd(char **path, char * prev, bool prevset)
{
if(path[1] == NULL)
{
printf("No argument for cd provided!\n");
}
else if(path[2] != NULL)
{
printf("cd: too many arguments!\n");
}
else if(!strcmp(path[1], "~"))
{
if(chdir(HOME) != 0)
{
perror("Error");
}
}
else if(!strcmp(path[1], "-"))
{
if(prevset)
{
if(chdir(prev) != 0)
{
perror("Error");
}
pwd();
}
else
{
printf("Error: No previous directory set yet\n");
}
}
else
{
if(chdir(path[1]) != 0)
{
perror("Error");
}
}
}