From: Ulrich Drepper Date: Thu, 17 Apr 1997 23:24:07 +0000 (+0000) Subject: (_getopt_initialize): Preserve optind. X-Git-Tag: cvs/libc20x-ud-970417~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d5a869794981148bc82e492ba4ce73be48ac9e7;p=thirdparty%2Fglibc.git (_getopt_initialize): Preserve optind. (_getopt_internal): Set optind to 1 if optind == 0 before calling _getopt_initialize (). --- diff --git a/posix/getopt.c b/posix/getopt.c index aa0c01ce596..4cbefa1f333 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; }