From ab310e1b1c2f85235e61c471802b53314da919f0 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 29 Nov 2008 06:49:36 +0000 Subject: apply post-1.13.0 patches --- libbb/getopt32.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libbb/getopt32.c') diff --git a/libbb/getopt32.c b/libbb/getopt32.c index 49fb533..17babcd 100644 --- a/libbb/getopt32.c +++ b/libbb/getopt32.c @@ -515,6 +515,19 @@ getopt32(char **argv, const char *applet_opts, ...) } } + /* In case getopt32 was already called: + * reset the libc getopt() function, which keeps internal state. + * run_nofork_applet_prime() does this, but we might end up here + * also via gunzip_main() -> gzip_main(). Play safe. + */ +#ifdef __GLIBC__ + optind = 0; +#else /* BSD style */ + optind = 1; + /* optreset = 1; */ +#endif + /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */ + pargv = NULL; /* Note: just "getopt() <= 0" will not work well for -- cgit v1.1