move iterate_on_dir() from e2fsprogs to libbb
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
87c40cf4de
commit
1746218bee
@ -8,33 +8,6 @@
|
|||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
#include "e2fs_lib.h"
|
#include "e2fs_lib.h"
|
||||||
|
|
||||||
#if INT_MAX == LONG_MAX
|
|
||||||
#define IF_LONG_IS_SAME(...) __VA_ARGS__
|
|
||||||
#define IF_LONG_IS_WIDER(...)
|
|
||||||
#else
|
|
||||||
#define IF_LONG_IS_SAME(...)
|
|
||||||
#define IF_LONG_IS_WIDER(...) __VA_ARGS__
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Iterate a function on each entry of a directory */
|
|
||||||
int iterate_on_dir(const char *dir_name,
|
|
||||||
int FAST_FUNC (*func)(const char *, struct dirent *, void *),
|
|
||||||
void *private)
|
|
||||||
{
|
|
||||||
DIR *dir;
|
|
||||||
struct dirent *de;
|
|
||||||
|
|
||||||
dir = opendir(dir_name);
|
|
||||||
if (dir == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
while ((de = readdir(dir)) != NULL) {
|
|
||||||
func(dir_name, de, private);
|
|
||||||
}
|
|
||||||
closedir(dir);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print file attributes on an ext2 file system */
|
/* Print file attributes on an ext2 file system */
|
||||||
const uint32_t e2attr_flags_value[] ALIGN4 = {
|
const uint32_t e2attr_flags_value[] ALIGN4 = {
|
||||||
#ifdef ENABLE_COMPRESSION
|
#ifdef ENABLE_COMPRESSION
|
||||||
|
@ -11,11 +11,6 @@
|
|||||||
|
|
||||||
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
|
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
|
||||||
|
|
||||||
/* Iterate a function on each entry of a directory */
|
|
||||||
int iterate_on_dir(const char *dir_name,
|
|
||||||
int FAST_FUNC (*func)(const char *, struct dirent *, void *),
|
|
||||||
void *private);
|
|
||||||
|
|
||||||
/* Print file attributes on an ext2 file system */
|
/* Print file attributes on an ext2 file system */
|
||||||
void print_e2flags_long(unsigned flags);
|
void print_e2flags_long(unsigned flags);
|
||||||
void print_e2flags(unsigned flags);
|
void print_e2flags(unsigned flags);
|
||||||
|
@ -512,6 +512,11 @@ int recursive_action(const char *fileName, unsigned flags,
|
|||||||
void *userData
|
void *userData
|
||||||
) FAST_FUNC;
|
) FAST_FUNC;
|
||||||
|
|
||||||
|
/* Simpler version: call a function on each dirent in a directory */
|
||||||
|
int iterate_on_dir(const char *dir_name,
|
||||||
|
int FAST_FUNC (*func)(const char *, struct dirent *, void *),
|
||||||
|
void *private) FAST_FUNC;
|
||||||
|
|
||||||
extern int device_open(const char *device, int mode) FAST_FUNC;
|
extern int device_open(const char *device, int mode) FAST_FUNC;
|
||||||
enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */
|
enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */
|
||||||
extern int xgetpty(char *line) FAST_FUNC;
|
extern int xgetpty(char *line) FAST_FUNC;
|
||||||
|
28
libbb/iterate_on_dir.c
Normal file
28
libbb/iterate_on_dir.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* vi: set sw=4 ts=4: */
|
||||||
|
/*
|
||||||
|
* See README for additional information
|
||||||
|
*
|
||||||
|
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||||
|
*/
|
||||||
|
//kbuild:lib-y += iterate_on_dir.o
|
||||||
|
|
||||||
|
#include "libbb.h"
|
||||||
|
|
||||||
|
/* Iterate a function on each entry of a directory */
|
||||||
|
int FAST_FUNC iterate_on_dir(const char *dir_name,
|
||||||
|
int FAST_FUNC (*func)(const char *, struct dirent *, void *),
|
||||||
|
void *private)
|
||||||
|
{
|
||||||
|
DIR *dir;
|
||||||
|
struct dirent *de;
|
||||||
|
|
||||||
|
dir = opendir(dir_name);
|
||||||
|
if (dir == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
while ((de = readdir(dir)) != NULL) {
|
||||||
|
func(dir_name, de, private);
|
||||||
|
}
|
||||||
|
closedir(dir);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user