-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.c
60 lines (49 loc) · 1.52 KB
/
test1.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
58
59
60
#include <stdio.h>
#include <comp421/iolib.h>
#include <comp421/filesystem.h>
#include <comp421/yalnix.h>
#include <string.h>
int main(int argc, char **argv) {
(void)argc;
(void)argv;
int fd;
int i;
char buf[DIRNAMELEN];
char tmp[DIRNAMELEN];
struct Stat statbuf;
sprintf(tmp, ".");
if (MkDir("dir")) {
printf("Something went wrong while making a directory\n");
}
for (i = 0; i < 10; i++) {
sprintf(buf, "/dir/%d", i);
printf("Creating file /dir/%d\n", i);
fd = Create(buf);
Stat(tmp, &statbuf);
ChDir("dir");
ChDir("..");
if (fd == ERROR) {
printf("Something went wrong creating file /dir/%d\n", i);
return ERROR;
} else {
strncpy(buf, "Hello world", DIRNAMELEN);
printf("Writing to file /dir/%d\n", i);
if (Write(fd, buf, (int)strlen(buf)) != (int)strlen(buf)) {
printf("Unable to write to file /dir/%d\n", i);
return ERROR;
}
if (Seek(fd, 0, SEEK_SET)) {
printf("Unable to seek to the beginning of file /dir/%d\n", i);
return ERROR;
}
if (Read(fd, buf, (int)strlen(buf)) != (int)strlen(buf)) {
printf("Unable to read back from file /dir/%d\n", i);
return ERROR;
}
printf("Read '%s' from file /dir/%d\n", buf, i);
}
}
printf("Wrote to all files\n");
Shutdown();
return 0;
}