1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:57:45 +00:00

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.
This commit is contained in:
Kenneth Myhra 2021-08-11 19:10:05 +02:00 committed by Linus Groh
parent 51b6bd8d95
commit 78eba1271f
2 changed files with 8 additions and 0 deletions

View file

@ -24,6 +24,13 @@ extern "C" {
DIR* opendir(const char* name) DIR* opendir(const char* name)
{ {
int fd = open(name, O_RDONLY | O_DIRECTORY); int fd = open(name, O_RDONLY | O_DIRECTORY);
if (fd == -1)
return nullptr;
return fdopendir(fd);
}
DIR* fdopendir(int fd)
{
if (fd == -1) if (fd == -1)
return nullptr; return nullptr;
DIR* dirp = (DIR*)malloc(sizeof(DIR)); DIR* dirp = (DIR*)malloc(sizeof(DIR));

View file

@ -27,6 +27,7 @@ struct __DIR {
}; };
typedef struct __DIR DIR; typedef struct __DIR DIR;
DIR* fdopendir(int fd);
DIR* opendir(const char* name); DIR* opendir(const char* name);
int closedir(DIR*); int closedir(DIR*);
void rewinddir(DIR*); void rewinddir(DIR*);