summaryrefslogtreecommitdiff
path: root/libshouldbeinlibc/options.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1995-05-22 18:10:57 +0000
committerMiles Bader <miles@gnu.org>1995-05-22 18:10:57 +0000
commitef9a23231951f40c290c8ed08a8d942427e3c5da (patch)
tree05d65b23cef0cfc64634c256ff3b4b67c473880d /libshouldbeinlibc/options.c
parent3daa2c9fce972720fae5671537243bdec48f7ebd (diff)
When adding a fake argv[0], bump argc.
Set optind to 0, so that getopt will reinitialize itself.
Diffstat (limited to 'libshouldbeinlibc/options.c')
-rw-r--r--libshouldbeinlibc/options.c5
1 files changed, 4 insertions, 1 deletions
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. */