diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-04 21:30:55 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-08-04 21:30:55 +0000 |
| commit | 82ad032e263de5d69a70cc9b169aab393f5a2b50 (patch) | |
| tree | 0a066bd8a2408974ed0b5acbacb47493ab08b243 | |
| parent | 855ff6f503ee50fad3eb6fa30e2b02f53f32d63d (diff) | |
| download | busybox-w32-82ad032e263de5d69a70cc9b169aab393f5a2b50.tar.gz busybox-w32-82ad032e263de5d69a70cc9b169aab393f5a2b50.tar.bz2 busybox-w32-82ad032e263de5d69a70cc9b169aab393f5a2b50.zip | |
xargs: fix -e default to match newer GNU xargs, add SUS mandated -E.
closes bug 4414
| -rw-r--r-- | findutils/xargs.c | 32 | ||||
| -rwxr-xr-x | testsuite/xargs.tests | 14 |
2 files changed, 29 insertions, 17 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c index 92d01f7b6..f22d089ca 100644 --- a/findutils/xargs.c +++ b/findutils/xargs.c | |||
| @@ -355,20 +355,22 @@ enum { | |||
| 355 | OPTBIT_UPTO_NUMBER, | 355 | OPTBIT_UPTO_NUMBER, |
| 356 | OPTBIT_UPTO_SIZE, | 356 | OPTBIT_UPTO_SIZE, |
| 357 | OPTBIT_EOF_STRING, | 357 | OPTBIT_EOF_STRING, |
| 358 | OPTBIT_EOF_STRING1, | ||
| 358 | USE_FEATURE_XARGS_SUPPORT_CONFIRMATION(OPTBIT_INTERACTIVE,) | 359 | USE_FEATURE_XARGS_SUPPORT_CONFIRMATION(OPTBIT_INTERACTIVE,) |
| 359 | USE_FEATURE_XARGS_SUPPORT_TERMOPT( OPTBIT_TERMINATE ,) | 360 | USE_FEATURE_XARGS_SUPPORT_TERMOPT( OPTBIT_TERMINATE ,) |
| 360 | USE_FEATURE_XARGS_SUPPORT_ZERO_TERM( OPTBIT_ZEROTERM ,) | 361 | USE_FEATURE_XARGS_SUPPORT_ZERO_TERM( OPTBIT_ZEROTERM ,) |
| 361 | 362 | ||
| 362 | OPT_VERBOSE = 1<<OPTBIT_VERBOSE , | 363 | OPT_VERBOSE = 1 << OPTBIT_VERBOSE , |
| 363 | OPT_NO_EMPTY = 1<<OPTBIT_NO_EMPTY , | 364 | OPT_NO_EMPTY = 1 << OPTBIT_NO_EMPTY , |
| 364 | OPT_UPTO_NUMBER = 1<<OPTBIT_UPTO_NUMBER, | 365 | OPT_UPTO_NUMBER = 1 << OPTBIT_UPTO_NUMBER, |
| 365 | OPT_UPTO_SIZE = 1<<OPTBIT_UPTO_SIZE , | 366 | OPT_UPTO_SIZE = 1 << OPTBIT_UPTO_SIZE , |
| 366 | OPT_EOF_STRING = 1<<OPTBIT_EOF_STRING , | 367 | OPT_EOF_STRING = 1 << OPTBIT_EOF_STRING , /* GNU: -e[<param>] */ |
| 367 | OPT_INTERACTIVE = USE_FEATURE_XARGS_SUPPORT_CONFIRMATION((1<<OPTBIT_INTERACTIVE)) + 0, | 368 | OPT_EOF_STRING1 = 1 << OPTBIT_EOF_STRING1, /* SUS: -E<param> */ |
| 368 | OPT_TERMINATE = USE_FEATURE_XARGS_SUPPORT_TERMOPT( (1<<OPTBIT_TERMINATE )) + 0, | 369 | OPT_INTERACTIVE = USE_FEATURE_XARGS_SUPPORT_CONFIRMATION((1 << OPTBIT_INTERACTIVE)) + 0, |
| 369 | OPT_ZEROTERM = USE_FEATURE_XARGS_SUPPORT_ZERO_TERM( (1<<OPTBIT_ZEROTERM )) + 0, | 370 | OPT_TERMINATE = USE_FEATURE_XARGS_SUPPORT_TERMOPT( (1 << OPTBIT_TERMINATE )) + 0, |
| 371 | OPT_ZEROTERM = USE_FEATURE_XARGS_SUPPORT_ZERO_TERM( (1 << OPTBIT_ZEROTERM )) + 0, | ||
| 370 | }; | 372 | }; |
| 371 | #define OPTION_STR "+trn:s:e::" \ | 373 | #define OPTION_STR "+trn:s:e::E:" \ |
| 372 | USE_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \ | 374 | USE_FEATURE_XARGS_SUPPORT_CONFIRMATION("p") \ |
| 373 | USE_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \ | 375 | USE_FEATURE_XARGS_SUPPORT_TERMOPT( "x") \ |
| 374 | USE_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") | 376 | USE_FEATURE_XARGS_SUPPORT_ZERO_TERM( "0") |
| @@ -376,8 +378,6 @@ enum { | |||
| 376 | int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 378 | int xargs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 377 | int xargs_main(int argc, char **argv) | 379 | int xargs_main(int argc, char **argv) |
| 378 | { | 380 | { |
| 379 | static const char const_eof_str[] ALIGN1 = "_"; | ||
| 380 | |||
| 381 | char **args; | 381 | char **args; |
| 382 | int i, n; | 382 | int i, n; |
| 383 | xlist_t *list = NULL; | 383 | xlist_t *list = NULL; |
| @@ -387,7 +387,7 @@ int xargs_main(int argc, char **argv) | |||
| 387 | int n_max_arg; | 387 | int n_max_arg; |
| 388 | size_t n_chars = 0; | 388 | size_t n_chars = 0; |
| 389 | long orig_arg_max; | 389 | long orig_arg_max; |
| 390 | const char *eof_str = const_eof_str; | 390 | const char *eof_str = NULL; |
| 391 | unsigned opt; | 391 | unsigned opt; |
| 392 | size_t n_max_chars; | 392 | size_t n_max_chars; |
| 393 | #if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM | 393 | #if ENABLE_FEATURE_XARGS_SUPPORT_ZERO_TERM |
| @@ -396,10 +396,12 @@ int xargs_main(int argc, char **argv) | |||
| 396 | #define read_args process_stdin | 396 | #define read_args process_stdin |
| 397 | #endif | 397 | #endif |
| 398 | 398 | ||
| 399 | opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &eof_str); | 399 | opt = getopt32(argv, OPTION_STR, &max_args, &max_chars, &eof_str, &eof_str); |
| 400 | 400 | ||
| 401 | /* -e without optional param? */ | 401 | /* -E ""? You may wonder why not just omit -E? |
| 402 | if ((opt & OPT_EOF_STRING) && eof_str == const_eof_str) | 402 | * This is used for portability: |
| 403 | * old xargs was using "_" as default for -E / -e */ | ||
| 404 | if ((opt & OPT_EOF_STRING1) && eof_str[0] == '\0') | ||
| 403 | eof_str = NULL; | 405 | eof_str = NULL; |
| 404 | 406 | ||
| 405 | if (opt & OPT_ZEROTERM) | 407 | if (opt & OPT_ZEROTERM) |
diff --git a/testsuite/xargs.tests b/testsuite/xargs.tests index e041d592e..36524499e 100755 --- a/testsuite/xargs.tests +++ b/testsuite/xargs.tests | |||
| @@ -6,14 +6,24 @@ | |||
| 6 | 6 | ||
| 7 | # testing "test name" "command" "expected result" "file input" "stdin" | 7 | # testing "test name" "command" "expected result" "file input" "stdin" |
| 8 | 8 | ||
| 9 | testing "xargs stops on underscore" \ | 9 | testing "xargs -E _ stops on underscore" \ |
| 10 | "xargs" \ | 10 | "xargs -E _" \ |
| 11 | "a\n" \ | 11 | "a\n" \ |
| 12 | "" "a\n_\nb\n" | 12 | "" "a\n_\nb\n" |
| 13 | 13 | ||
| 14 | testing "xargs -E ''" \ | ||
| 15 | "xargs -E ''" \ | ||
| 16 | "a _ b\n" \ | ||
| 17 | "" "a\n_\nb\n" | ||
| 18 | |||
| 14 | testing "xargs -e without param" \ | 19 | testing "xargs -e without param" \ |
| 15 | "xargs -e" \ | 20 | "xargs -e" \ |
| 16 | "a _ b\n" \ | 21 | "a _ b\n" \ |
| 17 | "" "a\n_\nb\n" | 22 | "" "a\n_\nb\n" |
| 18 | 23 | ||
| 24 | testing "xargs does not stop on underscore ('new' GNU behavior)" \ | ||
| 25 | "xargs" \ | ||
| 26 | "a _ b\n" \ | ||
| 27 | "" "a\n_\nb\n" | ||
| 28 | |||
| 19 | exit $FAILCOUNT | 29 | exit $FAILCOUNT |
