* lib/getopt.c (_getopt_internal_r): Use correct message for 'W;'
diagnostics. Honor '+:' correctly. Reject ';'.
Signed-off-by: Eric Blake <eblake@redhat.com>
2010-04-13 Eric Blake <eblake@redhat.com>
2010-04-13 Eric Blake <eblake@redhat.com>
+ getopt: merge bug fixes from glibc
+ * lib/getopt.c (_getopt_internal_r): Use correct message for 'W;'
+ diagnostics. Honor '+:' correctly. Reject ';'.
+
getopt-posix: detect MacOS bug
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Reject MacOS botch of
optind when missing a required argument.
getopt-posix: detect MacOS bug
* m4/getopt.m4 (gl_GETOPT_CHECK_HEADERS): Reject MacOS botch of
optind when missing a required argument.
int long_only, struct _getopt_data *d, int posixly_correct)
{
int print_errors = d->opterr;
int long_only, struct _getopt_data *d, int posixly_correct)
{
int print_errors = d->opterr;
- if (optstring[0] == ':')
- print_errors = 0;
posixly_correct);
d->__initialized = 1;
}
posixly_correct);
d->__initialized = 1;
}
+ else if (optstring[0] == '-' || optstring[0] == '+')
+ optstring++;
+ if (optstring[0] == ':')
+ print_errors = 0;
/* Test whether ARGV[optind] points to a non-option argument.
Either it does not have option syntax, or there is an environment flag
/* Test whether ARGV[optind] points to a non-option argument.
Either it does not have option syntax, or there is an environment flag
char *buf;
if (__asprintf (&buf, _("\
char *buf;
if (__asprintf (&buf, _("\
-%s: option '%s' requires an argument\n"),
- argv[0], argv[d->optind - 1]) >= 0)
+%s: option '--%s' requires an argument\n"),
+ argv[0], pfound->name) >= 0)
{
_IO_flockfile (stderr);
{
_IO_flockfile (stderr);
- _("%s: option '%s' requires an argument\n"),
- argv[0], argv[d->optind - 1]);
+ _("%s: option '--%s' requires an argument\n"),
+ argv[0], pfound->name);
#endif
}
d->__nextchar += strlen (d->__nextchar);
#endif
}
d->__nextchar += strlen (d->__nextchar);
if (*d->__nextchar == '\0')
++d->optind;
if (*d->__nextchar == '\0')
++d->optind;
- if (temp == NULL || c == ':')
+ if (temp == NULL || c == ':' || c == ';')
pfound = p;
indfound = option_index;
}
pfound = p;
indfound = option_index;
}
+ else if (long_only
+ || pfound->has_arg != p->has_arg
+ || pfound->flag != p->flag
+ || pfound->val != p->val)
/* Second or later nonexact match found. */
ambig = 1;
}
/* Second or later nonexact match found. */
ambig = 1;
}
char *buf;
if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
char *buf;
if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
- argv[0], argv[d->optind]) >= 0)
+ argv[0], d->optarg) >= 0)
{
_IO_flockfile (stderr);
{
_IO_flockfile (stderr);
}
#else
fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
}
#else
fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
- argv[0], argv[d->optind]);
#endif
}
d->__nextchar += strlen (d->__nextchar);
#endif
}
d->__nextchar += strlen (d->__nextchar);
char *buf;
if (__asprintf (&buf, _("\
char *buf;
if (__asprintf (&buf, _("\
-%s: option '%s' requires an argument\n"),
- argv[0], argv[d->optind - 1]) >= 0)
+%s: option '-W %s' requires an argument\n"),
+ argv[0], pfound->name) >= 0)
{
_IO_flockfile (stderr);
{
_IO_flockfile (stderr);
- fprintf (stderr,
- _("%s: option '%s' requires an argument\n"),
- argv[0], argv[d->optind - 1]);
+ fprintf (stderr, _("\
+%s: option '-W %s' requires an argument\n"),
+ argv[0], pfound->name);
#endif
}
d->__nextchar += strlen (d->__nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
#endif
}
d->__nextchar += strlen (d->__nextchar);
return optstring[0] == ':' ? ':' : '?';
}
}
+ else
+ d->optarg = NULL;
d->__nextchar += strlen (d->__nextchar);
if (longind != NULL)
*longind = option_index;
d->__nextchar += strlen (d->__nextchar);
if (longind != NULL)
*longind = option_index;