diff options
author | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-15 13:28:46 +0000 |
---|---|---|
committer | vda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-03-15 13:28:46 +0000 |
commit | 74fc4f8167d8dbee89c076bab9d6214f0176f02c (patch) | |
tree | c81c3ba07136f42fe81835e4720c180dcc0f2583 | |
parent | f10971e4997d50bd72bdcf14154ba4007d1b65a1 (diff) | |
download | busybox-w32-74fc4f8167d8dbee89c076bab9d6214f0176f02c.tar.gz busybox-w32-74fc4f8167d8dbee89c076bab9d6214f0176f02c.tar.bz2 busybox-w32-74fc4f8167d8dbee89c076bab9d6214f0176f02c.zip |
fix TODO: getopt32 should reset optind to 1 itself
git-svn-id: svn://busybox.net/trunk/busybox@18118 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | archival/gzip.c | 2 | ||||
-rw-r--r-- | libbb/getopt32.c | 8 |
2 files changed, 6 insertions, 4 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 68f1cc87d..6af6c1886 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -2041,8 +2041,6 @@ int gzip_main(int argc, char **argv) | |||
2041 | //if (opt & 0x4) // -v | 2041 | //if (opt & 0x4) // -v |
2042 | #if ENABLE_GUNZIP /* gunzip_main may not be visible... */ | 2042 | #if ENABLE_GUNZIP /* gunzip_main may not be visible... */ |
2043 | if (opt & 0x8) { // -d | 2043 | if (opt & 0x8) { // -d |
2044 | /* FIXME: getopt32 should not depend on optind */ | ||
2045 | optind = 1; | ||
2046 | return gunzip_main(argc, argv); | 2044 | return gunzip_main(argc, argv); |
2047 | } | 2045 | } |
2048 | #endif | 2046 | #endif |
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 9f5fd60bd..6cdbfd35d 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c | |||
@@ -454,6 +454,10 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
454 | spec_flgs |= FREE_FIRST_ARGV_IS_OPT; | 454 | spec_flgs |= FREE_FIRST_ARGV_IS_OPT; |
455 | } | 455 | } |
456 | } | 456 | } |
457 | |||
458 | /* In case getopt32 was already called, reinit some state */ | ||
459 | optind = 1; | ||
460 | |||
457 | /* Note: just "getopt() <= 0" will not work good for | 461 | /* Note: just "getopt() <= 0" will not work good for |
458 | * "fake" short options, like this one: | 462 | * "fake" short options, like this one: |
459 | * wget $'-\203' "Test: test" http://kernel.org/ | 463 | * wget $'-\203' "Test: test" http://kernel.org/ |
@@ -463,9 +467,9 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) | |||
463 | applet_long_options, NULL)) != -1) { | 467 | applet_long_options, NULL)) != -1) { |
464 | #else | 468 | #else |
465 | while ((c = getopt(argc, argv, applet_opts)) != -1) { | 469 | while ((c = getopt(argc, argv, applet_opts)) != -1) { |
466 | #endif /* ENABLE_GETOPT_LONG */ | 470 | #endif |
467 | c &= 0xff; /* fight libc's sign extends */ | 471 | c &= 0xff; /* fight libc's sign extends */ |
468 | loop_arg_is_opt: | 472 | loop_arg_is_opt: |
469 | for (on_off = complementary; on_off->opt != c; on_off++) { | 473 | for (on_off = complementary; on_off->opt != c; on_off++) { |
470 | /* c==0 if long opt have non NULL flag */ | 474 | /* c==0 if long opt have non NULL flag */ |
471 | if (on_off->opt == 0 && c != 0) | 475 | if (on_off->opt == 0 && c != 0) |