From ef9a23231951f40c290c8ed08a8d942427e3c5da Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Mon, 22 May 1995 18:10:57 +0000 Subject: When adding a fake argv[0], bump argc. Set optind to 0, so that getopt will reinitialize itself. --- libshouldbeinlibc/options.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libshouldbeinlibc') diff --git a/libshouldbeinlibc/options.c b/libshouldbeinlibc/options.c index e0c4b0c5..b0b93aea 100644 --- a/libshouldbeinlibc/options.c +++ b/libshouldbeinlibc/options.c @@ -165,6 +165,9 @@ options_parse (struct options *options, /* Getopt is (currently) non-reentrant. */ mutex_lock (&getopt_lock); + /* Tell getopt to initialize. */ + optind = 0; + if (flags & OPTIONS_PRINT_ERRS) opterr = 1; /* Print error messages. */ else @@ -173,7 +176,7 @@ options_parse (struct options *options, if (!(flags & OPTIONS_SKIP_ARG0)) /* getopt always skips ARGV[0], so we have to fake it out. As long as opterr is 0, then it shouldn't actually try to access it. */ - argv--; + argv--, argc++; } /* Now use getopt on our coalesced options lists. */ -- cgit v1.2.3