LibC: Implement scandir(...) to enumerate directories.

I ran into a need for this when running  stress-ng against the system.
This change implements the full functionality of scandir, where it
accepts a selection callback, as well as a comparison callback.
These can be used to trim and sort the entries from the directory
that we are being asked to enumerate. A test was also included to
validate the new functionality.
This commit is contained in:
Brian Gianforcaro 2021-05-02 02:36:59 -07:00 committed by Andreas Kling
commit 331ab52318
Notes: sideshowbarker 2024-07-18 18:47:14 +09:00
4 changed files with 95 additions and 0 deletions

View file

@ -55,4 +55,8 @@ struct dirent* readdir(DIR*);
int readdir_r(DIR*, struct dirent*, struct dirent**);
int dirfd(DIR*);
int scandir(const char* dirp, struct dirent*** namelist,
int (*filter)(const struct dirent*),
int (*compar)(const struct dirent**, const struct dirent**));
__END_DECLS