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:
parent
51b6bd8d95
commit
78eba1271f
2 changed files with 8 additions and 0 deletions
|
@ -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));
|
||||||
|
|
|
@ -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*);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue