-
Notifications
You must be signed in to change notification settings - Fork 3
/
jobs.c
58 lines (50 loc) · 1.29 KB
/
jobs.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
53
54
55
56
57
/* COMP 530: Tar Heel SHell
*
* This file implements functions related to launching
* jobs and job control.
*/
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "thsh.h"
static char ** path_table;
/* Initialize the table of PATH prefixes.
*
* Split the result on the parenteses, and
* remove any trailing '/' characters.
* The last entry should be a NULL character.
*
* For instance, if one's PATH environment variable is:
* /bin:/sbin///
*
* Then path_table should be:
* path_table[0] = "/bin"
* path_table[1] = "/sbin"
* path_table[2] = '\0'
*
* Hint: take a look at getenv(). If you use getenv, do NOT
* modify the resulting string directly, but use
* malloc() or another function to allocate space and copy.
*
* Returns 0 on success, -errno on failure.
*/
int init_path(void) {
/* Lab 1: Your code here */
return 0;
}
/* Debug helper function that just prints
* the path table out.
*/
void print_path_table() {
if (path_table == NULL) {
printf("XXXXXXX Path Table Not Initialized XXXXX\n");
return;
}
printf("===== Begin Path Table =====\n");
for (int i = 0; path_table[i]; i++) {
printf("Prefix %2d: [%s]\n", i, path_table[i]);
}
printf("===== End Path Table =====\n");
}