#include <fcntl.h>
#include <string.h>
#include <sys/lxdirent.h>
+#include <unistd.h>
DIR*
opendir(const char* dir)
return NULL;
}
- _dir = (DIR){ .dirfd = fd, .prev_res = 0 };
+ _dir = (DIR){ .dirfd = fd };
return &_dir;
}
+int
+closedir(DIR* dirp)
+{
+ if (!dirp || dirp->dirfd == -1) {
+ // TODO migrate the status.h
+ return -1;
+ }
+
+ int err = close(dirp->dirfd);
+
+ if (!err) {
+ dirp->dirfd = -1;
+ return 0;
+ }
+
+ return -1;
+}
+
struct dirent*
readdir(DIR* dir)
{
return NULL;
}
- struct lx_dirent _lxd;
- int more = sys_readdir(dir->dirfd, &_lxd);
+ struct lx_dirent* _lxd = &dir->_lxd;
+
+ int more = sys_readdir(dir->dirfd, _lxd);
- _dirent.d_type = _lxd.d_type;
- strncpy(_dirent.d_name, _lxd.d_name, 256);
+ _dirent.d_type = _lxd->d_type;
+ strncpy(_dirent.d_name, _lxd->d_name, 256);
- if (more || dir->prev_res) {
- dir->prev_res = more;
+ if (more) {
return &_dirent;
}
- if (!dir->prev_res) {
- return NULL;
- }
+ return NULL;
}
\ No newline at end of file