diff options
author | Denis Vlasenko | 2007-03-15 13:28:46 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-03-15 13:28:46 +0000 |
commit | 24af7201e98a9692e1dfa9976c1a6ba97013ca23 (patch) | |
tree | c81c3ba07136f42fe81835e4720c180dcc0f2583 /libbb/getopt32.c | |
parent | 972288e62fa0798f59caf209ab58c911d289a8b2 (diff) | |
download | busybox-24af7201e98a9692e1dfa9976c1a6ba97013ca23.zip busybox-24af7201e98a9692e1dfa9976c1a6ba97013ca23.tar.gz |
fix TODO: getopt32 should reset optind to 1 itself
Diffstat (limited to 'libbb/getopt32.c')
-rw-r--r-- | libbb/getopt32.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 9f5fd60..6cdbfd3 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -454,6 +454,10 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) spec_flgs |= FREE_FIRST_ARGV_IS_OPT; } } + + /* In case getopt32 was already called, reinit some state */ + optind = 1; + /* Note: just "getopt() <= 0" will not work good for * "fake" short options, like this one: * wget $'-\203' "Test: test" http://kernel.org/ @@ -463,9 +467,9 @@ getopt32(int argc, char **argv, const char *applet_opts, ...) applet_long_options, NULL)) != -1) { #else while ((c = getopt(argc, argv, applet_opts)) != -1) { -#endif /* ENABLE_GETOPT_LONG */ +#endif c &= 0xff; /* fight libc's sign extends */ -loop_arg_is_opt: + loop_arg_is_opt: for (on_off = complementary; on_off->opt != c; on_off++) { /* c==0 if long opt have non NULL flag */ if (on_off->opt == 0 && c != 0) |