14 DIR *opendir(char *path
)
18 if ((fd
= open(path
, O_RDONLY
| O_DIRECTORY
)) < 0)
20 fcntl(fd
, F_SETFD
, fcntl(fd
, F_GETFD
) | FD_CLOEXEC
);
21 if (!(dir
= malloc(sizeof(*dir
)))) {
25 memset(dir
, 0, sizeof(*dir
));
30 int closedir(DIR *dir
)
38 int getdents(int fd
, struct dirent
*de
, size_t len
);
40 struct dirent
*readdir(DIR *dir
)
44 if (dir
->buf_pos
>= dir
->buf_end
) {
45 len
= getdents(dir
->fd
, (void *) dir
->buf
, sizeof(dir
->buf
));
51 de
= (void *) (dir
->buf
+ dir
->buf_pos
);
52 dir
->buf_pos
+= de
->d_reclen
;