From 3e816c1252cc55e3763f946622129d31ea1f0f20 Mon Sep 17 00:00:00 2001 From: Bernhard Reutner-Fischer Date: Thu, 29 Mar 2007 10:30:50 +0000 Subject: - fold recurse, depthFirst and dereference params into one param flags. Minor size improvement (-16b for size, -24b according to bloat-o-meter). --- archival/tar.c | 5 +++-- coreutils/chmod.c | 2 -- coreutils/chown.c | 13 ++++++------- coreutils/diff.c | 3 ++- debianutils/run_parts.c | 4 +--- findutils/find.c | 14 ++++++-------- findutils/grep.c | 6 +++--- include/libbb.h | 9 ++++++--- libbb/recursive_action.c | 41 ++++++++++++++++++++--------------------- modutils/insmod.c | 4 ++-- selinux/chcon.c | 4 +--- 11 files changed, 50 insertions(+), 55 deletions(-) diff --git a/archival/tar.c b/archival/tar.c index 176a7e22d..5a6ef60db 100644 --- a/archival/tar.c +++ b/archival/tar.c @@ -562,8 +562,9 @@ static int writeTarFile(const int tar_fd, const int verboseFlag, /* Read the directory/files and iterate over them one at a time */ while (include) { - if (!recursive_action(include->data, TRUE, dereferenceFlag, - FALSE, writeFileToTarball, writeFileToTarball, &tbInfo, 0)) + if (!recursive_action(include->data, (action_recurse | + dereferenceFlag ? action_followLinks : 0), + writeFileToTarball, writeFileToTarball, &tbInfo, 0)) { errorFlag = TRUE; } diff --git a/coreutils/chmod.c b/coreutils/chmod.c index 11c6731a1..9a73218a1 100644 --- a/coreutils/chmod.c +++ b/coreutils/chmod.c @@ -101,8 +101,6 @@ int chmod_main(int argc, char **argv) do { if (!recursive_action(*argv, OPT_RECURSE, // recurse - FALSE, // follow links: coreutils doesn't - FALSE, // depth first fileAction, // file action fileAction, // dir action smode, // user data diff --git a/coreutils/chown.c b/coreutils/chown.c index f92299e36..09b1a595b 100644 --- a/coreutils/chown.c +++ b/coreutils/chown.c @@ -92,13 +92,12 @@ int chown_main(int argc, char **argv) } if (!recursive_action(arg, - OPT_RECURSE, // recurse - OPT_TRAVERSE, // follow links if -L - FALSE, // depth first - fileAction, // file action - fileAction, // dir action - chown_func, // user data - 0) // depth + (OPT_RECURSE ? action_recurse : 0 | /* recurse */ + OPT_TRAVERSE ? action_followLinks : 0),/* follow links if -L */ + fileAction, /* file action */ + fileAction, /* dir action */ + chown_func, /* user data */ + 0) /* depth */ ) { retval = EXIT_FAILURE; } diff --git a/coreutils/diff.c b/coreutils/diff.c index 911bfcf4d..1903bb151 100644 --- a/coreutils/diff.c +++ b/coreutils/diff.c @@ -1079,7 +1079,8 @@ static char **get_dir(char *path) * add_to_dirlist then removes root dir prefix. */ if (option_mask32 & FLAG_r) { - recursive_action(path, TRUE, TRUE, FALSE, add_to_dirlist, NULL, + recursive_action(path, action_recurse|action_followLinks, + add_to_dirlist, NULL, (void*)(strlen(path)+1), 0); } else { DIR *dp; diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c index b41045a36..c67072730 100644 --- a/debianutils/run_parts.c +++ b/debianutils/run_parts.c @@ -138,9 +138,7 @@ int run_parts_main(int argc, char **argv) G.cmd[tmp] = arg_list->data; /* G.cmd[tmp] = NULL; - G is already zeroed out */ if (!recursive_action(argv[argc - 1], - TRUE, /* recurse */ - TRUE, /* follow links */ - FALSE, /* depth first */ + action_recurse|action_followLinks, act, /* file action */ act, /* dir action */ NULL, /* user data */ diff --git a/findutils/find.c b/findutils/find.c index e98d995a4..c043fbc7d 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -574,7 +574,7 @@ static action*** parse_params(char **argv) int find_main(int argc, char **argv); int find_main(int argc, char **argv) { - int dereference = FALSE; + bool dereference = FALSE; char *arg; char **argp; int i, firstopt, status = EXIT_SUCCESS; @@ -632,13 +632,11 @@ int find_main(int argc, char **argv) for (i = 1; i < firstopt; i++) { if (!recursive_action(argv[i], - TRUE, // recurse - dereference, // follow links - FALSE, // depth first - fileAction, // file action - fileAction, // dir action - NULL, // user data - 0)) // depth + action_recurse|(1<d_name); if (nextFile == NULL) continue; - if (!recursive_action(nextFile, TRUE, followLinks, depthFirst, + /* now descend into it, forcing recursion. */ + if (!recursive_action(nextFile, flags | action_recurse, fileAction, dirAction, userData, depth+1)) { status = FALSE; } free(nextFile); } closedir(dir); - if (depthFirst) { - if (!dirAction(fileName, &statbuf, userData, depth)) { - bb_perror_msg("%s", fileName); - return FALSE; - } + if (flags & action_depthFirst && + !dirAction(fileName, &statbuf, userData, depth)) { + goto done_nak_warn; } if (!status) return FALSE; return TRUE; +done_nak_warn: + bb_perror_msg("%s", fileName); + return FALSE; } diff --git a/modutils/insmod.c b/modutils/insmod.c index 57092f79a..075969dcb 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c @@ -4044,7 +4044,7 @@ int insmod_main( int argc, char **argv) module_dir = tmdn; else module_dir = real_module_dir; - recursive_action(module_dir, TRUE, FALSE, FALSE, + recursive_action(module_dir, action_recurse, check_module_name_match, 0, m_fullName, 0); free(tmdn); } @@ -4059,7 +4059,7 @@ int insmod_main( int argc, char **argv) strcpy(module_dir, _PATH_MODULES); /* No module found under /lib/modules/`uname -r`, this * time cast the net a bit wider. Search /lib/modules/ */ - if (!recursive_action(module_dir, TRUE, FALSE, FALSE, + if (!recursive_action(module_dir, action_recurse, check_module_name_match, 0, m_fullName, 0) ) { if (m_filename == 0 diff --git a/selinux/chcon.c b/selinux/chcon.c index 72cfa93c3..0eab6864e 100644 --- a/selinux/chcon.c +++ b/selinux/chcon.c @@ -163,9 +163,7 @@ int chcon_main(int argc, char *argv[]) fname[fname_len] = '\0'; if (recursive_action(fname, - option_mask32 & OPT_RECURSIVE, - FALSE, /* followLinks */ - FALSE, /* depthFirst */ + 1<