summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c
index b9a41f4..8bb80c0 100644
--- a/src/io.c
+++ b/src/io.c
@@ -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));