From a8226de3e53937b579705586a16ccc884b8efb5d Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Thu, 3 Oct 2024 14:20:51 +0200 Subject: libc: Add fdopendir() --- include/dirent.h | 1 + userland/libc/dirent/opendir.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/dirent.h b/include/dirent.h index b986ddb..dcd7f59 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -22,6 +22,7 @@ typedef struct { #ifndef KERNEL DIR *opendir(const char *dirname); +DIR *fdopendir(int fd); struct dirent *readdir(DIR *dir); int closedir(DIR *dirp); int alphasort(const struct dirent **d1, const struct dirent **d2); diff --git a/userland/libc/dirent/opendir.c b/userland/libc/dirent/opendir.c index 7bfa562..efe8b6d 100644 --- a/userland/libc/dirent/opendir.c +++ b/userland/libc/dirent/opendir.c @@ -1,10 +1,24 @@ #include +DIR *fdopendir(int fd) { + DIR *rc = malloc(sizeof(DIR)); + if (!rc) { + return NULL; + } + rc->fd = fd; + rc->dir_num = 0; + return rc; +} + DIR *opendir(const char *dirname) { int fd = open(dirname, O_RDONLY, 0); - if (-1 == fd) + if (-1 == fd) { return NULL; + } DIR *rc = malloc(sizeof(DIR)); + if (!rc) { + return NULL; + } rc->fd = fd; rc->dir_num = 0; return rc; -- cgit v1.2.3