CS350 COS
COS
Loading...
Searching...
No Matches
dir.c
Go to the documentation of this file.
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
10DIR *
11opendir(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
24struct dirent *
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
35void
37{
38 d->offset = 0;
39}
40
41void
42seekdir(DIR *d, long offset)
43{
44 d->offset = offset;
45}
46
47long
49{
50 return d->offset;
51}
52
53int
55{
56 OSClose(d->fd);
57 free(d);
58
59 return 0;
60}
61
int closedir(DIR *d)
Definition: dir.c:54
void rewinddir(DIR *d)
Definition: dir.c:36
struct dirent * readdir(DIR *d)
Definition: dir.c:25
void seekdir(DIR *d, long offset)
Definition: dir.c:42
long telldir(DIR *d)
Definition: dir.c:48
DIR * opendir(const char *path)
Definition: dir.c:11
uint64_t offset
Definition: dirent.h:9
struct dirent de
Definition: dirent.h:10
int fd
Definition: dirent.h:8
Definition: dirent.h:7
uint64_t OSOpen(const char *path, uint64_t flags)
Definition: syscall.c:77
int OSClose(uint64_t fd)
Definition: syscall.c:83
int OSReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset)
Definition: syscall.c:95
#define NULL
Definition: stddef.h:6
void free(void *buf)
Definition: malloc.c:169
void * malloc(size_t sz)
Definition: malloc.c:160
Definition: dirent.h:9