aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-24 11:42:55 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-24 11:42:55 +0200
commit1746218beebc7e180f3eaed905277f9f46983ac4 (patch)
treef3649cc92207d437b9ce2b635e22a13154978a3e /libbb
parent87c40cf4de435d1b19b7fb545a495542c6eaf820 (diff)
downloadbusybox-w32-1746218beebc7e180f3eaed905277f9f46983ac4.tar.gz
busybox-w32-1746218beebc7e180f3eaed905277f9f46983ac4.tar.bz2
busybox-w32-1746218beebc7e180f3eaed905277f9f46983ac4.zip
move iterate_on_dir() from e2fsprogs to libbb
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/iterate_on_dir.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/libbb/iterate_on_dir.c b/libbb/iterate_on_dir.c
new file mode 100644
index 000000000..deef72ebf
--- /dev/null
+++ b/libbb/iterate_on_dir.c
@@ -0,0 +1,28 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * See README for additional information
4 *
5 * Licensed under GPLv2, see file LICENSE in this source tree.
6 */
7//kbuild:lib-y += iterate_on_dir.o
8
9#include "libbb.h"
10
11/* Iterate a function on each entry of a directory */
12int FAST_FUNC iterate_on_dir(const char *dir_name,
13 int FAST_FUNC (*func)(const char *, struct dirent *, void *),
14 void *private)
15{
16 DIR *dir;
17 struct dirent *de;
18
19 dir = opendir(dir_name);
20 if (dir == NULL) {
21 return -1;
22 }
23 while ((de = readdir(dir)) != NULL) {
24 func(dir_name, de, private);
25 }
26 closedir(dir);
27 return 0;
28}