diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-24 11:42:55 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2021-06-24 11:42:55 +0200 |
commit | 1746218beebc7e180f3eaed905277f9f46983ac4 (patch) | |
tree | f3649cc92207d437b9ce2b635e22a13154978a3e | |
parent | 87c40cf4de435d1b19b7fb545a495542c6eaf820 (diff) | |
download | busybox-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>
-rw-r--r-- | e2fsprogs/e2fs_lib.c | 27 | ||||
-rw-r--r-- | e2fsprogs/e2fs_lib.h | 5 | ||||
-rw-r--r-- | include/libbb.h | 5 | ||||
-rw-r--r-- | libbb/iterate_on_dir.c | 28 |
4 files changed, 33 insertions, 32 deletions
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c index e32336ae6..9b68d8901 100644 --- a/e2fsprogs/e2fs_lib.c +++ b/e2fsprogs/e2fs_lib.c | |||
@@ -8,33 +8,6 @@ | |||
8 | #include "libbb.h" | 8 | #include "libbb.h" |
9 | #include "e2fs_lib.h" | 9 | #include "e2fs_lib.h" |
10 | 10 | ||
11 | #if INT_MAX == LONG_MAX | ||
12 | #define IF_LONG_IS_SAME(...) __VA_ARGS__ | ||
13 | #define IF_LONG_IS_WIDER(...) | ||
14 | #else | ||
15 | #define IF_LONG_IS_SAME(...) | ||
16 | #define IF_LONG_IS_WIDER(...) __VA_ARGS__ | ||
17 | #endif | ||
18 | |||
19 | /* Iterate a function on each entry of a directory */ | ||
20 | int iterate_on_dir(const char *dir_name, | ||
21 | int FAST_FUNC (*func)(const char *, struct dirent *, void *), | ||
22 | void *private) | ||
23 | { | ||
24 | DIR *dir; | ||
25 | struct dirent *de; | ||
26 | |||
27 | dir = opendir(dir_name); | ||
28 | if (dir == NULL) { | ||
29 | return -1; | ||
30 | } | ||
31 | while ((de = readdir(dir)) != NULL) { | ||
32 | func(dir_name, de, private); | ||
33 | } | ||
34 | closedir(dir); | ||
35 | return 0; | ||
36 | } | ||
37 | |||
38 | /* Print file attributes on an ext2 file system */ | 11 | /* Print file attributes on an ext2 file system */ |
39 | const uint32_t e2attr_flags_value[] ALIGN4 = { | 12 | const uint32_t e2attr_flags_value[] ALIGN4 = { |
40 | #ifdef ENABLE_COMPRESSION | 13 | #ifdef ENABLE_COMPRESSION |
diff --git a/e2fsprogs/e2fs_lib.h b/e2fsprogs/e2fs_lib.h index 879272f44..bab447a94 100644 --- a/e2fsprogs/e2fs_lib.h +++ b/e2fsprogs/e2fs_lib.h | |||
@@ -11,11 +11,6 @@ | |||
11 | 11 | ||
12 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | 12 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
13 | 13 | ||
14 | /* Iterate a function on each entry of a directory */ | ||
15 | int iterate_on_dir(const char *dir_name, | ||
16 | int FAST_FUNC (*func)(const char *, struct dirent *, void *), | ||
17 | void *private); | ||
18 | |||
19 | /* Print file attributes on an ext2 file system */ | 14 | /* Print file attributes on an ext2 file system */ |
20 | void print_e2flags_long(unsigned flags); | 15 | void print_e2flags_long(unsigned flags); |
21 | void print_e2flags(unsigned flags); | 16 | void print_e2flags(unsigned flags); |
diff --git a/include/libbb.h b/include/libbb.h index 251d7231c..7d6ab4a93 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -512,6 +512,11 @@ int recursive_action(const char *fileName, unsigned flags, | |||
512 | void *userData | 512 | void *userData |
513 | ) FAST_FUNC; | 513 | ) FAST_FUNC; |
514 | 514 | ||
515 | /* Simpler version: call a function on each dirent in a directory */ | ||
516 | int iterate_on_dir(const char *dir_name, | ||
517 | int FAST_FUNC (*func)(const char *, struct dirent *, void *), | ||
518 | void *private) FAST_FUNC; | ||
519 | |||
515 | extern int device_open(const char *device, int mode) FAST_FUNC; | 520 | extern int device_open(const char *device, int mode) FAST_FUNC; |
516 | enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */ | 521 | enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */ |
517 | extern int xgetpty(char *line) FAST_FUNC; | 522 | extern int xgetpty(char *line) FAST_FUNC; |
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 */ | ||
12 | int 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 | } | ||