summaryrefslogtreecommitdiff
path: root/posix/getopt.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1997-04-17 23:24:07 +0000
committerUlrich Drepper <drepper@redhat.com>1997-04-17 23:24:07 +0000
commit3d5a869794981148bc82e492ba4ce73be48ac9e7 (patch)
tree8eb9c555e7cfff703c2612ef3c0d8f7ba01b13df /posix/getopt.c
parent12fc66d6513a65d37c4584d95416a7970a62f3c8 (diff)
(_getopt_initialize): Preserve optind.
(_getopt_internal): Set optind to 1 if optind == 0 before calling _getopt_initialize ().
Diffstat (limited to 'posix/getopt.c')
-rw-r--r--posix/getopt.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/posix/getopt.c b/posix/getopt.c
index aa0c01ce59..4cbefa1f33 100644
--- a/posix/getopt.c
+++ b/posix/getopt.c
@@ -253,7 +253,9 @@ static int last_nonopt;
/* Bash 2.0 gives us an environment variable containing flags
indicating ARGV elements that should not be considered arguments. */
-char *__getopt_nonoption_flags;
+/* Defined in getopt_init.c */
+extern char *__getopt_nonoption_flags;
+
static int nonoption_flags_max_len;
static int nonoption_flags_len;
@@ -395,7 +397,7 @@ _getopt_initialize (argc, argv, optstring)
is the program name); the sequence of previously skipped
non-option ARGV-elements is empty. */
- first_nonopt = last_nonopt = optind = 1;
+ first_nonopt = last_nonopt = optind;
nextchar = NULL;
@@ -521,10 +523,11 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only)
{
optarg = NULL;
- if (!__getopt_initialized || optind == 0)
+ if (optind == 0 || !__getopt_initialized)
{
+ if (optind == 0)
+ optind = 1; /* Don't scan ARGV[0], the program name. */
optstring = _getopt_initialize (argc, argv, optstring);
- optind = 1; /* Don't scan ARGV[0], the program name. */
__getopt_initialized = 1;
}