diff --git a/lib/libc/include/dirent.h b/lib/libc/include/dirent.h new file mode 100644 index 0000000..69abd3c --- /dev/null +++ b/lib/libc/include/dirent.h @@ -0,0 +1,13 @@ +#ifndef DIRENT_H_ +#define DIRENT_H_ + +#define DT_UNKNOWN 0 +#define DT_BLK 1 +#define DT_CHR 2 +#define DT_DIR 3 +#define DT_FIFO 4 +#define DT_LNK 5 +#define DT_REG 6 +#define DT_SOCK 7 + +#endif diff --git a/lib/libc/include/sys/types.h b/lib/libc/include/sys/types.h index 91b81e8..7f6b647 100644 --- a/lib/libc/include/sys/types.h +++ b/lib/libc/include/sys/types.h @@ -7,4 +7,11 @@ #define SEEK_CUR 1 #define SEEK_END 2 +struct dentry { + unsigned long d_ino; + unsigned short d_reclen; + char d_type; + char d_name[]; +}; + #endif diff --git a/lib/libc/include/unistd.h b/lib/libc/include/unistd.h index 2932824..b7f2365 100644 --- a/lib/libc/include/unistd.h +++ b/lib/libc/include/unistd.h @@ -12,4 +12,6 @@ extern int write(int fd, const void *buf, size_t count); extern off_t lseek(int fd, off_t offset, int whence); +extern long getdents(int fd, struct dentry *dirp, unsigned int count); + #endif diff --git a/lib/libc/io/unistd/getdents.c b/lib/libc/io/unistd/getdents.c new file mode 100644 index 0000000..99c75c3 --- /dev/null +++ b/lib/libc/io/unistd/getdents.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include +#include + +int getdents(int fd, struct dentry *dirp, unsigned int count) +{ + int err; + size_t nr_read = 0; + kern_status_t status = fs_getdents(fd, &err, dirp, count, &nr_read); + if (status != KERN_OK) { + return __set_errno(__errno_from_kern_status(status)); + } + + if (err != SUCCESS) { + return __set_errno(err); + } + + return nr_read; +}