-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltIn.c
More file actions
48 lines (45 loc) · 947 Bytes
/
builtIn.c
File metadata and controls
48 lines (45 loc) · 947 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
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <fcntl.h>
void status(int exitStatus, int killedBySig)
{
if (killedBySig == 0)
{
// last command not killed by signal
printf("exit value %d\n", exitStatus);
fflush(stdout);
}
else
{
// last command was killed by a signal
printf("terminated by signal %d\n", exitStatus);
fflush(stdout);
}
}
void cd(char *args[])
{
if (args[1] == NULL)
{
// no second arg provided, cd to home dir
if (chdir(getenv("HOME")) != 0)
{
perror("ERROR");
fflush(stderr);
}
}
else
{
// second arg privided, attempt to cd to given dir
if (chdir(args[1]) != 0)
{
perror("ERROR");
fflush(stderr);
}
}
return;
}