lib: c: io: implement getdents()
This commit is contained in:
13
lib/libc/include/dirent.h
Normal file
13
lib/libc/include/dirent.h
Normal file
@@ -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
|
||||||
@@ -7,4 +7,11 @@
|
|||||||
#define SEEK_CUR 1
|
#define SEEK_CUR 1
|
||||||
#define SEEK_END 2
|
#define SEEK_END 2
|
||||||
|
|
||||||
|
struct dentry {
|
||||||
|
unsigned long d_ino;
|
||||||
|
unsigned short d_reclen;
|
||||||
|
char d_type;
|
||||||
|
char d_name[];
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -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 off_t lseek(int fd, off_t offset, int whence);
|
||||||
|
|
||||||
|
extern long getdents(int fd, struct dentry *dirp, unsigned int count);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
22
lib/libc/io/unistd/getdents.c
Normal file
22
lib/libc/io/unistd/getdents.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <mango/handle.h>
|
||||||
|
#include <mango/msg.h>
|
||||||
|
#include <rosetta/fs.h>
|
||||||
|
#include <sys/remote.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user