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 @@ -24,6 +24,13 @@ extern "C" { 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)); 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*);