aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-03-20 22:17:13 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-03-20 22:17:13 +0000
commit83518d18a34a3ddfcaac1739930d8469f5bc2442 (patch)
tree2af665365a69f2689288cc13bb65efbb59e7d520 /findutils
parent0b28103cc774eb1ee62362cf61d52c32d44ec2cf (diff)
downloadbusybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.tar.gz
busybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.tar.bz2
busybox-w32-83518d18a34a3ddfcaac1739930d8469f5bc2442.zip
Compatibility fixes:
grep: support -z find: support --mindepth together +45 bytes cpio: support -p (configurable, +230 bytes) libbb: tweaks for cpio
Diffstat (limited to 'findutils')
-rw-r--r--findutils/find.c22
-rw-r--r--findutils/grep.c17
2 files changed, 25 insertions, 14 deletions
diff --git a/findutils/find.c b/findutils/find.c
index f2b89746f..df632f219 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -381,9 +381,11 @@ static int FAST_FUNC fileAction(const char *fileName,
381{ 381{
382 int i; 382 int i;
383#if ENABLE_FEATURE_FIND_MAXDEPTH 383#if ENABLE_FEATURE_FIND_MAXDEPTH
384 int maxdepth = (int)(ptrdiff_t)userData; 384#define minmaxdepth ((int*)userData)
385 385
386 if (depth > maxdepth) return SKIP; 386 if (depth < minmaxdepth[0]) return TRUE;
387 if (depth > minmaxdepth[1]) return SKIP;
388#undef minmaxdepth
387#endif 389#endif
388 390
389#if ENABLE_FEATURE_FIND_XDEV 391#if ENABLE_FEATURE_FIND_XDEV
@@ -812,19 +814,21 @@ int find_main(int argc, char **argv)
812 static const char options[] ALIGN1 = 814 static const char options[] ALIGN1 =
813 "-follow\0" 815 "-follow\0"
814USE_FEATURE_FIND_XDEV( "-xdev\0" ) 816USE_FEATURE_FIND_XDEV( "-xdev\0" )
815USE_FEATURE_FIND_MAXDEPTH("-maxdepth\0") 817USE_FEATURE_FIND_MAXDEPTH("-mindepth\0""-maxdepth\0")
816 ; 818 ;
817 enum { 819 enum {
818 OPT_FOLLOW, 820 OPT_FOLLOW,
819USE_FEATURE_FIND_XDEV( OPT_XDEV ,) 821USE_FEATURE_FIND_XDEV( OPT_XDEV ,)
820USE_FEATURE_FIND_MAXDEPTH(OPT_MAXDEPTH,) 822USE_FEATURE_FIND_MAXDEPTH(OPT_MINDEPTH,)
821 }; 823 };
822 824
823 char *arg; 825 char *arg;
824 char **argp; 826 char **argp;
825 int i, firstopt, status = EXIT_SUCCESS; 827 int i, firstopt, status = EXIT_SUCCESS;
826#if ENABLE_FEATURE_FIND_MAXDEPTH 828#if ENABLE_FEATURE_FIND_MAXDEPTH
827 int maxdepth = INT_MAX; 829 int minmaxdepth[2] = { 0, INT_MAX };
830#else
831#define minmaxdepth NULL
828#endif 832#endif
829 833
830 for (firstopt = 1; firstopt < argc; firstopt++) { 834 for (firstopt = 1; firstopt < argc; firstopt++) {
@@ -875,10 +879,10 @@ USE_FEATURE_FIND_MAXDEPTH(OPT_MAXDEPTH,)
875 } 879 }
876#endif 880#endif
877#if ENABLE_FEATURE_FIND_MAXDEPTH 881#if ENABLE_FEATURE_FIND_MAXDEPTH
878 if (opt == OPT_MAXDEPTH) { 882 if (opt == OPT_MINDEPTH || opt == OPT_MINDEPTH + 1) {
879 if (!argp[1]) 883 if (!argp[1])
880 bb_show_usage(); 884 bb_show_usage();
881 maxdepth = xatoi_u(argp[1]); 885 minmaxdepth[opt - OPT_MINDEPTH] = xatoi_u(argp[1]);
882 argp[0] = (char*)"-a"; 886 argp[0] = (char*)"-a";
883 argp[1] = (char*)"-a"; 887 argp[1] = (char*)"-a";
884 argp++; 888 argp++;
@@ -895,9 +899,7 @@ USE_FEATURE_FIND_MAXDEPTH(OPT_MAXDEPTH,)
895 fileAction, /* file action */ 899 fileAction, /* file action */
896 fileAction, /* dir action */ 900 fileAction, /* dir action */
897#if ENABLE_FEATURE_FIND_MAXDEPTH 901#if ENABLE_FEATURE_FIND_MAXDEPTH
898 /* double cast suppresses 902 minmaxdepth, /* user data */
899 * "cast to ptr from int of different size" */
900 (void*)(ptrdiff_t)maxdepth,/* user data */
901#else 903#else
902 NULL, /* user data */ 904 NULL, /* user data */
903#endif 905#endif
diff --git a/findutils/grep.c b/findutils/grep.c
index 6a6ddb679..723c3511a 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -28,7 +28,9 @@
28 USE_FEATURE_GREP_CONTEXT("A:B:C:") \ 28 USE_FEATURE_GREP_CONTEXT("A:B:C:") \
29 USE_FEATURE_GREP_EGREP_ALIAS("E") \ 29 USE_FEATURE_GREP_EGREP_ALIAS("E") \
30 USE_DESKTOP("w") \ 30 USE_DESKTOP("w") \
31 USE_EXTRA_COMPAT("z") \
31 "aI" 32 "aI"
33
32/* ignored: -a "assume all files to be text" */ 34/* ignored: -a "assume all files to be text" */
33/* ignored: -I "assume binary files have no matches" */ 35/* ignored: -I "assume binary files have no matches" */
34 36
@@ -54,6 +56,7 @@ enum {
54 USE_FEATURE_GREP_CONTEXT( OPTBIT_C ,) /* -C NUM: -A and -B combined */ 56 USE_FEATURE_GREP_CONTEXT( OPTBIT_C ,) /* -C NUM: -A and -B combined */
55 USE_FEATURE_GREP_EGREP_ALIAS(OPTBIT_E ,) /* extended regexp */ 57 USE_FEATURE_GREP_EGREP_ALIAS(OPTBIT_E ,) /* extended regexp */
56 USE_DESKTOP( OPTBIT_w ,) /* whole word match */ 58 USE_DESKTOP( OPTBIT_w ,) /* whole word match */
59 USE_EXTRA_COMPAT( OPTBIT_z ,) /* input is NUL terminated */
57 OPT_l = 1 << OPTBIT_l, 60 OPT_l = 1 << OPTBIT_l,
58 OPT_n = 1 << OPTBIT_n, 61 OPT_n = 1 << OPTBIT_n,
59 OPT_q = 1 << OPTBIT_q, 62 OPT_q = 1 << OPTBIT_q,
@@ -75,6 +78,7 @@ enum {
75 OPT_C = USE_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 0, 78 OPT_C = USE_FEATURE_GREP_CONTEXT( (1 << OPTBIT_C)) + 0,
76 OPT_E = USE_FEATURE_GREP_EGREP_ALIAS((1 << OPTBIT_E)) + 0, 79 OPT_E = USE_FEATURE_GREP_EGREP_ALIAS((1 << OPTBIT_E)) + 0,
77 OPT_w = USE_DESKTOP( (1 << OPTBIT_w)) + 0, 80 OPT_w = USE_DESKTOP( (1 << OPTBIT_w)) + 0,
81 OPT_z = USE_EXTRA_COMPAT( (1 << OPTBIT_z)) + 0,
78}; 82};
79 83
80#define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l) 84#define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l)
@@ -84,6 +88,7 @@ enum {
84#define PRINT_MATCH_COUNTS (option_mask32 & OPT_c) 88#define PRINT_MATCH_COUNTS (option_mask32 & OPT_c)
85#define FGREP_FLAG (option_mask32 & OPT_F) 89#define FGREP_FLAG (option_mask32 & OPT_F)
86#define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L) 90#define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L)
91#define NUL_DELIMITED (option_mask32 & OPT_z)
87 92
88struct globals { 93struct globals {
89 int max_matches; 94 int max_matches;
@@ -186,7 +191,7 @@ static void print_line(const char *line, size_t line_len, int linenum, char deco
186 puts(line); 191 puts(line);
187#else 192#else
188 fwrite(line, 1, line_len, stdout); 193 fwrite(line, 1, line_len, stdout);
189 putchar('\n'); 194 putchar(NUL_DELIMITED ? '\0' : '\n');
190#endif 195#endif
191 } 196 }
192} 197}
@@ -197,12 +202,13 @@ static ssize_t FAST_FUNC bb_getline(char **line_ptr, size_t *line_alloc_len, FIL
197{ 202{
198 ssize_t res_sz; 203 ssize_t res_sz;
199 char *line; 204 char *line;
205 int delim = (NUL_DELIMITED ? '\0' : '\n');
200 206
201 res_sz = getline(line_ptr, line_alloc_len, file); 207 res_sz = getdelim(line_ptr, line_alloc_len, delim, file);
202 line = *line_ptr; 208 line = *line_ptr;
203 209
204 if (res_sz > 0) { 210 if (res_sz > 0) {
205 if (line[res_sz - 1] == '\n') 211 if (line[res_sz - 1] == delim)
206 line[--res_sz] = '\0'; 212 line[--res_sz] = '\0';
207 } else { 213 } else {
208 free(line); /* uclibc allocates a buffer even on EOF. WTF? */ 214 free(line); /* uclibc allocates a buffer even on EOF. WTF? */
@@ -407,8 +413,11 @@ static int grep_file(FILE *file)
407#endif 413#endif
408 /* Did we print all context after last requested match? */ 414 /* Did we print all context after last requested match? */
409 if ((option_mask32 & OPT_m) 415 if ((option_mask32 & OPT_m)
410 && !print_n_lines_after && nmatches == max_matches) 416 && !print_n_lines_after
417 && nmatches == max_matches
418 ) {
411 break; 419 break;
420 }
412 } /* while (read line) */ 421 } /* while (read line) */
413 422
414 /* special-case file post-processing for options where we don't print line 423 /* special-case file post-processing for options where we don't print line