-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcom_cd.h
More file actions
56 lines (54 loc) · 993 Bytes
/
Copy pathcom_cd.h
File metadata and controls
56 lines (54 loc) · 993 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef COM_CD_H
#define COM_CD_H
#include "global.h"
int call_cd()
{
if (numargs > 2)
{
printf("cd: Too many arguments\n");
return 0;
}
char temppwd[1000];
strcpy(temppwd, lastpwd);
struct utsname xname;
uname(&xname);
char *result = getcwd(lastpwd, sizeof(lastpwd));
if (numargs == 1)
{
int ret = chdir(shelldir);
if (ret == -1)
{
perror("cd");
return 0;
}
return 1;
}
// ~ flag for cd
if (commands[1][0] == '~')
{
chdir(shelldir);
if (strlen(commands[1]) > 2)
{
commands[1]++;
commands[1]++;
}
else
{
return 1;
}
}
// - flag for cd
if (strcmp(commands[1], "-") == 0)
{
chdir(temppwd);
return 1;
}
int ret = chdir(commands[1]);
if (ret == -1)
{
perror("cd");
return 0;
}
return 1;
}
#endif