36 lines
572 B
C
36 lines
572 B
C
#include "dir.h"
|
|
|
|
#include <dirent.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
struct dirent *readdir(struct __opaque_dir *dirp)
|
|
{
|
|
int result = __libc_dir_move_next(dirp);
|
|
if (result < 0) {
|
|
dirp->d_flags |= DIR_ERR;
|
|
__set_errno(-result);
|
|
return NULL;
|
|
}
|
|
|
|
if (result > 0) {
|
|
return &dirp->d_current;
|
|
}
|
|
|
|
result = __libc_dir_refill(dirp);
|
|
if (result < 0) {
|
|
dirp->d_flags |= DIR_ERR;
|
|
__set_errno(-result);
|
|
return NULL;
|
|
}
|
|
|
|
if (!dirp->d_buf_datalen) {
|
|
return NULL;
|
|
}
|
|
|
|
return &dirp->d_current;
|
|
}
|