15 DIR *opendir(char *path
)
19 if ((fd
= open(path
, O_RDONLY
| O_DIRECTORY
)) < 0)
21 fcntl(fd
, F_SETFD
, fcntl(fd
, F_GETFD
) | FD_CLOEXEC
);
22 if (!(dir
= malloc(sizeof(*dir
)))) {
26 memset(dir
, 0, sizeof(*dir
));
31 int closedir(DIR *dir
)
39 int getdents(int fd
, struct dirent
*de
, size_t len
);
41 struct dirent
*readdir(DIR *dir
)
45 if (dir
->buf_pos
>= dir
->buf_end
) {
46 len
= getdents(dir
->fd
, (void *) dir
->buf
, sizeof(dir
->buf
));
52 de
= (void *) (dir
->buf
+ dir
->buf_pos
);
53 dir
->buf_pos
+= de
->d_reclen
;