123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #include "dirent.h"
- #include "unistd.h"
- #include "stdio.h"
- #include "fcntl.h"
- #include "stddef.h"
- #include "stdlib.h"
- #include "string.h"
- #include <libsystem/syscall.h>
- struct DIR *opendir(const char *path)
- {
- int fd = open(path, O_DIRECTORY);
- if (fd < 0)
- {
- printf("Failed to open dir\n");
- return NULL;
- }
-
-
- struct DIR *dirp = (struct DIR *)malloc(sizeof(struct DIR));
-
- memset(dirp, 0, sizeof(struct DIR));
- dirp->fd = fd;
- dirp->buf_len = DIR_BUF_SIZE;
- dirp->buf_pos = 0;
- return dirp;
- }
- int closedir(struct DIR *dirp)
- {
- int retval = close(dirp->fd);
- free(dirp);
- return retval;
- }
- int64_t getdents(int fd, struct dirent *dirent, long count)
- {
- return syscall_invoke(SYS_GET_DENTS, fd, (uint64_t)dirent, count, 0, 0, 0, 0, 0);
- }
- struct dirent *readdir(struct DIR *dir)
- {
-
- memset((dir->buf), 0, DIR_BUF_SIZE);
-
- int len = getdents(dir->fd, (struct dirent *)dir->buf, DIR_BUF_SIZE);
-
- if (len > 0)
- return (struct dirent *)dir->buf;
- else
- return NULL;
- }
|