/* 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;
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;
{
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;
}