diff options
Diffstat (limited to 'src/io.c')
-rw-r--r-- | src/io.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -14,6 +14,7 @@ #include <fcntl.h> #include <unistd.h> #include <malloc.h> +#include <dirent.h> #include <sys/mman.h> #include <sys/wait.h> #include <sys/stat.h> @@ -542,6 +543,32 @@ int apk_file_get_info(int atfd, const char *filename, unsigned int flags, return 0; } +int apk_dir_foreach_file(int dirfd, apk_dir_file_cb cb, void *ctx) +{ + struct dirent *de; + DIR *dir; + + if (dirfd < 0) + return -1; + + dir = fdopendir(dirfd); + if (dir == NULL) + return -1; + + /* We get called here with dup():ed fd. Since they all refer to + * same object, we need to rewind so subsequent calls work. */ + rewinddir(dir); + + while ((de = readdir(dir)) != NULL) { + if (de->d_name[0] == '.') + continue; + cb(ctx, de->d_name); + } + closedir(dir); + + return 0; +} + struct apk_istream *apk_istream_from_file_gz(int atfd, const char *file) { return apk_bstream_gunzip(apk_bstream_from_file(atfd, file)); |