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() --- userland/libc/dirent/opendir.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'userland/libc/dirent/opendir.c') 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