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