-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
51 lines (36 loc) · 879 Bytes
/
test.c
File metadata and controls
51 lines (36 loc) · 879 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
#include <stdio.h>
#include <stdlib.h>
#include <spawn.h>
#include <sys/wait.h>
#include <unistd.h>
#include <string.h>
#define N 12
extern char **environ;
char *allowed[N] = {"cp","touch","mkdir","ls","pwd","cat","grep","chmod","diff","cd","exit","help"};
int isAllowed(const char*cmd) {
// return 1 if cmd is one of the allowed commands
// return 0 otherwise
for (int i=0;i<N;i++) {
if (allowed[i]==cmd){
return(1);
}
}
return 0;
}
int main() {
char line[256];
int count;
fgets(line,256,stdin);
//count how many arguments there are going to be
for (int i=0; i<strlen(line); i++) {
if (pathName[i]==' '){
count++;
}
}
char *argv[20];
nexttoken=strtok(tmp," ");
if (isAllowed("askdf")) {
printf("eyy");
}
return 0;
}