1 
2 #include <stdint.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 #include <dirent.h>
8 #include <syscall.h>
9 
10 DIR *
opendir(const char * path)11 opendir(const char *path)
12 {
13     DIR *d = (DIR *)malloc(sizeof(DIR));
14 
15     d->fd = OSOpen(path, 0);
16     if (d->fd < 0) {
17 	free(d);
18 	return NULL;
19     }
20 
21     return d;
22 }
23 
24 struct dirent *
readdir(DIR * d)25 readdir(DIR *d)
26 {
27     int status = OSReadDir(d->fd, (char *)&d->de, sizeof(struct dirent), &d->offset);
28     if (status == 0) {
29 	return NULL;
30     }
31 
32     return &d->de;
33 }
34 
35 void
rewinddir(DIR * d)36 rewinddir(DIR *d)
37 {
38     d->offset = 0;
39 }
40 
41 void
seekdir(DIR * d,long offset)42 seekdir(DIR *d, long offset)
43 {
44     d->offset = offset;
45 }
46 
47 long
telldir(DIR * d)48 telldir(DIR *d)
49 {
50     return d->offset;
51 }
52 
53 int
closedir(DIR * d)54 closedir(DIR *d)
55 {
56     OSClose(d->fd);
57     free(d);
58 
59     return 0;
60 }
61 
62