summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibC
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2021-08-11 19:10:05 +0200
committerLinus Groh <mail@linusgroh.de>2021-08-14 22:32:00 +0100
commit78eba1271f194b4ce2bd57d886a483702c38ee51 (patch)
tree3f6ebfd8a3a962ca549ebd7fc2a3db6d9d00435a /Userland/Libraries/LibC
parent51b6bd8d956443112d21cfabfc22f55e17b01456 (diff)
downloadserenity-78eba1271f194b4ce2bd57d886a483702c38ee51.zip
LibC: Add function fdopendir
This adds the function fdopendir and refactors opendir so that opendir just opens a file descriptor and passes the file descriptor onto fdopendir.
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r--Userland/Libraries/LibC/dirent.cpp7
-rw-r--r--Userland/Libraries/LibC/dirent.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/dirent.cpp b/Userland/Libraries/LibC/dirent.cpp
index 7475d22519..3447b9d370 100644
--- a/Userland/Libraries/LibC/dirent.cpp
+++ b/Userland/Libraries/LibC/dirent.cpp
@@ -26,6 +26,13 @@ DIR* opendir(const char* name)
int fd = open(name, O_RDONLY | O_DIRECTORY);
if (fd == -1)
return nullptr;
+ return fdopendir(fd);
+}
+
+DIR* fdopendir(int fd)
+{
+ if (fd == -1)
+ return nullptr;
DIR* dirp = (DIR*)malloc(sizeof(DIR));
dirp->fd = fd;
dirp->buffer = nullptr;
diff --git a/Userland/Libraries/LibC/dirent.h b/Userland/Libraries/LibC/dirent.h
index e78114bb6d..1e3f8534cc 100644
--- a/Userland/Libraries/LibC/dirent.h
+++ b/Userland/Libraries/LibC/dirent.h
@@ -27,6 +27,7 @@ struct __DIR {
};
typedef struct __DIR DIR;
+DIR* fdopendir(int fd);
DIR* opendir(const char* name);
int closedir(DIR*);
void rewinddir(DIR*);