forked from WesleyGlover/Linux-Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcd.c
More file actions
38 lines (31 loc) · 580 Bytes
/
cd.c
File metadata and controls
38 lines (31 loc) · 580 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
37
38
#include "major2.h"
#define HOME "/home"
char* setUpChangeDir(char** path)
{
char* rPath;
rPath = malloc(500);
for(int i = 1; i < 500; i++)
{
if(path[i] == NULL)
break;
strcat(rPath, path[i]);
if(path[i+1] == NULL)
break;
strcat(rPath, " ");
}
return rPath;
}
void changeDirectory(char* path)
{
if(strcmp(path, "") == 0)
{
chdir(HOME);
}
else
{
if(chdir(path) == -1)
{
printf("cd: %s: does not exist\n", path);
}
}
};