libc: Implement dirfd, rewinddir, telldir and seekdir
This commit is contained in:
parent
e457b88b04
commit
865018e7f8
@ -36,6 +36,18 @@ extern "C"
|
|||||||
* calls to readdir(). */
|
* calls to readdir(). */
|
||||||
struct dirent* readdir(DIR* stream);
|
struct dirent* readdir(DIR* stream);
|
||||||
|
|
||||||
|
/* Returns the file descriptor associated with stream. */
|
||||||
|
int dirfd(DIR* stream);
|
||||||
|
|
||||||
|
/* Positions stream's offset at the start of the directory. */
|
||||||
|
void rewinddir(DIR* stream);
|
||||||
|
|
||||||
|
/* Returns the current offset position for stream. */
|
||||||
|
long telldir(DIR* stream);
|
||||||
|
|
||||||
|
/* Moves stream's read offset to offset, which should be the return value of a previous call to telldir(). */
|
||||||
|
void seekdir(DIR* stream, long offset);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -10,9 +10,9 @@ extern "C"
|
|||||||
{
|
{
|
||||||
DIR* opendir(const char* path)
|
DIR* opendir(const char* path)
|
||||||
{
|
{
|
||||||
int dirfd = open(path, O_RDONLY | O_DIRECTORY);
|
int fd = open(path, O_RDONLY | O_DIRECTORY);
|
||||||
if (dirfd < 0) return NULL;
|
if (fd < 0) return NULL;
|
||||||
return fdopendir(dirfd);
|
return fdopendir(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
DIR* fdopendir(int fd)
|
DIR* fdopendir(int fd)
|
||||||
@ -50,4 +50,24 @@ extern "C"
|
|||||||
strlcpy(result.d_name, ent.name, NAME_MAX);
|
strlcpy(result.d_name, ent.name, NAME_MAX);
|
||||||
return &result;
|
return &result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int dirfd(DIR* stream)
|
||||||
|
{
|
||||||
|
return stream->d_dirfd;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rewinddir(DIR* stream)
|
||||||
|
{
|
||||||
|
lseek(stream->d_dirfd, 0, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
long telldir(DIR* stream)
|
||||||
|
{
|
||||||
|
return lseek(stream->d_dirfd, 0, SEEK_CUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
void seekdir(DIR* stream, long offset)
|
||||||
|
{
|
||||||
|
lseek(stream->d_dirfd, offset, SEEK_SET);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user