LibC: Implement the rewinddir() function

This commit is contained in:
Gunnar Beutner 2021-04-25 09:41:45 +02:00 committed by Andreas Kling
parent 8d6e9fad40
commit 2447dcd1ea
Notes: sideshowbarker 2024-07-18 19:07:37 +09:00
2 changed files with 11 additions and 2 deletions

View File

@ -35,8 +35,7 @@ int closedir(DIR* dirp)
{
if (!dirp || dirp->fd == -1)
return -EBADF;
if (dirp->buffer)
free(dirp->buffer);
free(dirp->buffer);
int rc = close(dirp->fd);
if (rc == 0)
dirp->fd = -1;
@ -44,6 +43,15 @@ int closedir(DIR* dirp)
return rc;
}
void rewinddir(DIR* dirp)
{
free(dirp->buffer);
dirp->buffer = nullptr;
dirp->buffer_size = 0;
dirp->nextptr = nullptr;
lseek(dirp->fd, 0, SEEK_SET);
}
struct [[gnu::packed]] sys_dirent {
ino_t ino;
u8 file_type;

View File

@ -50,6 +50,7 @@ typedef struct __DIR DIR;
DIR* opendir(const char* name);
int closedir(DIR*);
void rewinddir(DIR*);
struct dirent* readdir(DIR*);
int readdir_r(DIR*, struct dirent*, struct dirent**);
int dirfd(DIR*);