-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin.c
More file actions
59 lines (58 loc) · 1.04 KB
/
builtin.c
File metadata and controls
59 lines (58 loc) · 1.04 KB
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
57
58
59
#include "simpleshell.h"
/**
*sxit - cheack for ue
*@eke: kdskk
*Return: 1 for success and 0 if NULL
*/
int sxit(char **eke);
int sxit(char **eke)
{
char buff[1024];
char *update, *statpassed;
int exitstat = 0;
if (strcmp(eke[0], "exit") == 0)
{
if (eke[1] == NULL)
{
free(eke[0]);
exit(exitstat);
}
else
{
statpassed = eke[1];
exitstat = atoi(statpassed);
free(eke[0]);
exit(exitstat);
}
}
else if (strcmp(eke[0], "cd") == 0)
{
if (eke[1] == NULL)
{
chdir(getenv("HOME"));
getcwd(buff, 1024);
update = getenv("PWD");
setenv("OLDPWD", update, 1);
setenv("PWD", buff, 1);
}
else if (strcmp(eke[1], "-") == 0)
{
chdir(getenv("OLDPWD"));
getcwd(buff, 1024);
update = getenv("PWD");
setenv("OLDPWD", update, 1);
setenv("PWD", buff, 1);
}
else
{
if (chdir(eke[1]) != 0)
fprintf(stderr, "./hsh: 1: cd: can't cd to %s\n", eke[1]);
getcwd(buff, 1024);
update = getenv("PWD");
setenv("OLDPWD", update, 1);
setenv("PWD", buff, 1);
}
return (1);
}
return (0);
}