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 */
iterate_on_dir(const char * dir_name,int FAST_FUNC (* func)(const char *,struct dirent *,void *),void * private)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 }
29