]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(_getopt_initialize): Preserve optind.
authorUlrich Drepper <drepper@redhat.com>
Thu, 17 Apr 1997 23:24:07 +0000 (23:24 +0000)
committerUlrich Drepper <drepper@redhat.com>
Thu, 17 Apr 1997 23:24:07 +0000 (23:24 +0000)
(_getopt_internal): Set optind to 1 if optind == 0 before
calling _getopt_initialize ().

posix/getopt.c

index aa0c01ce596cbfc3a9d86e3a80a0614540a859bf..4cbefa1f33397bb73621e7b0356ee0bd1b40345b 100644 (file)
@@ -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;
     }