aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-11-12 08:27:51 +0000
committerRon Yorston <rmy@pobox.com>2020-11-12 08:27:51 +0000
commitead8b92e3d66ab45235e137f85fb3a529dcc64ef (patch)
treeaf268270382dad969218063d4a8120fc91a9e631 /findutils
parent567728c22dddea4ed33b8a69641ba2e0c3f1f600 (diff)
parent64981b4c8e88812c322bee3832f1d421ff670ed5 (diff)
downloadbusybox-w32-ead8b92e3d66ab45235e137f85fb3a529dcc64ef.tar.gz
busybox-w32-ead8b92e3d66ab45235e137f85fb3a529dcc64ef.tar.bz2
busybox-w32-ead8b92e3d66ab45235e137f85fb3a529dcc64ef.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'findutils')
-rw-r--r--findutils/find.c17
-rw-r--r--findutils/grep.c24
-rw-r--r--findutils/xargs.c21
3 files changed, 36 insertions, 26 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 121f8fd03..f26c01c1e 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -889,10 +889,10 @@ ACTF(links)
889} 889}
890#endif 890#endif
891 891
892static int FAST_FUNC fileAction(const char *fileName, 892static int FAST_FUNC fileAction(
893 struct stat *statbuf, 893 struct recursive_state *state IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM),
894 void *userData UNUSED_PARAM, 894 const char *fileName,
895 int depth IF_NOT_FEATURE_FIND_MAXDEPTH(UNUSED_PARAM)) 895 struct stat *statbuf)
896{ 896{
897 int r; 897 int r;
898 int same_fs = 1; 898 int same_fs = 1;
@@ -911,12 +911,12 @@ static int FAST_FUNC fileAction(const char *fileName,
911#endif 911#endif
912 912
913#if ENABLE_FEATURE_FIND_MAXDEPTH 913#if ENABLE_FEATURE_FIND_MAXDEPTH
914 if (depth < G.minmaxdepth[0]) { 914 if (state->depth < G.minmaxdepth[0]) {
915 if (same_fs) 915 if (same_fs)
916 return TRUE; /* skip this, continue recursing */ 916 return TRUE; /* skip this, continue recursing */
917 return SKIP; /* stop recursing */ 917 return SKIP; /* stop recursing */
918 } 918 }
919 if (depth > G.minmaxdepth[1]) 919 if (state->depth > G.minmaxdepth[1])
920 return SKIP; /* stop recursing */ 920 return SKIP; /* stop recursing */
921#endif 921#endif
922 922
@@ -927,7 +927,7 @@ static int FAST_FUNC fileAction(const char *fileName,
927 927
928#if ENABLE_FEATURE_FIND_MAXDEPTH 928#if ENABLE_FEATURE_FIND_MAXDEPTH
929 if (S_ISDIR(statbuf->st_mode)) { 929 if (S_ISDIR(statbuf->st_mode)) {
930 if (depth == G.minmaxdepth[1]) 930 if (state->depth == G.minmaxdepth[1])
931 return SKIP; 931 return SKIP;
932 } 932 }
933#endif 933#endif
@@ -1574,8 +1574,7 @@ int find_main(int argc UNUSED_PARAM, char **argv)
1574 G.recurse_flags,/* flags */ 1574 G.recurse_flags,/* flags */
1575 fileAction, /* file action */ 1575 fileAction, /* file action */
1576 fileAction, /* dir action */ 1576 fileAction, /* dir action */
1577 NULL, /* user data */ 1577 NULL) /* user data */
1578 0) /* depth */
1579 ) { 1578 ) {
1580 G.exitstatus |= EXIT_FAILURE; 1579 G.exitstatus |= EXIT_FAILURE;
1581 } 1580 }
diff --git a/findutils/grep.c b/findutils/grep.c
index b456ed467..10cca83e7 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -656,10 +656,9 @@ static void load_pattern_list(llist_t **lst, char *pattern)
656 llist_add_to(lst, new_grep_list_data(p, 0)); 656 llist_add_to(lst, new_grep_list_data(p, 0));
657} 657}
658 658
659static int FAST_FUNC file_action_grep(const char *filename, 659static int FAST_FUNC file_action_grep(struct recursive_state *state UNUSED_PARAM,
660 struct stat *statbuf, 660 const char *filename,
661 void* matched, 661 struct stat *statbuf)
662 int depth UNUSED_PARAM)
663{ 662{
664 FILE *file; 663 FILE *file;
665 664
@@ -686,7 +685,7 @@ static int FAST_FUNC file_action_grep(const char *filename,
686 return 0; 685 return 0;
687 } 686 }
688 cur_file = filename; 687 cur_file = filename;
689 *(int*)matched |= grep_file(file); 688 *(int*)state->userData |= grep_file(file);
690 fclose(file); 689 fclose(file);
691 return 1; 690 return 1;
692} 691}
@@ -694,15 +693,16 @@ static int FAST_FUNC file_action_grep(const char *filename,
694static int grep_dir(const char *dir) 693static int grep_dir(const char *dir)
695{ 694{
696 int matched = 0; 695 int matched = 0;
697 recursive_action(dir, 696 recursive_action(dir, 0
698 /* recurse=yes */ ACTION_RECURSE | 697 | ACTION_RECURSE
699 /* followLinks=always */ ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0) | 698 | ((option_mask32 & OPT_R) ? ACTION_FOLLOWLINKS : 0)
700 /* followLinks=command line only */ ACTION_FOLLOWLINKS_L0 | 699 | ACTION_FOLLOWLINKS_L0 /* grep -r ... SYMLINK follows it */
701 /* depthFirst=yes */ ACTION_DEPTHFIRST, 700 | ACTION_DEPTHFIRST
701 | 0,
702 /* fileAction= */ file_action_grep, 702 /* fileAction= */ file_action_grep,
703 /* dirAction= */ NULL, 703 /* dirAction= */ NULL,
704 /* userData= */ &matched, 704 /* userData= */ &matched
705 /* depth= */ 0); 705 );
706 return matched; 706 return matched;
707} 707}
708 708
diff --git a/findutils/xargs.c b/findutils/xargs.c
index 71350d470..1f8d95168 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -83,9 +83,11 @@
83/* This is a NOEXEC applet. Be very careful! */ 83/* This is a NOEXEC applet. Be very careful! */
84 84
85 85
86//#define dbg_msg(...) bb_error_msg(__VA_ARGS__) 86#if 0
87#define dbg_msg(...) ((void)0) 87# define dbg_msg(...) bb_error_msg(__VA_ARGS__)
88 88#else
89# define dbg_msg(...) ((void)0)
90#endif
89 91
90#ifdef TEST 92#ifdef TEST
91# ifndef ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION 93# ifndef ENABLE_FEATURE_XARGS_SUPPORT_CONFIRMATION
@@ -539,9 +541,18 @@ static char* FAST_FUNC process_stdin_with_replace(int n_max_chars, int n_max_arg
539 541
540 while (1) { 542 while (1) {
541 int c = getchar(); 543 int c = getchar();
544 if (p == buf) {
545 if (c == EOF)
546 goto ret; /* last line is empty, return "" */
547 if (c == G.eol_ch)
548 continue; /* empty line, ignore */
549 /* Skip leading whitespace of each line: try
550 * echo -e ' \t\v1 2 3 ' | xargs -I% echo '[%]'
551 */
552 if (ISSPACE(c))
553 continue;
554 }
542 if (c == EOF || c == G.eol_ch) { 555 if (c == EOF || c == G.eol_ch) {
543 if (p == buf)
544 goto ret; /* empty line */
545 c = '\0'; 556 c = '\0';
546 } 557 }
547 *p++ = c; 558 *p++ = c;