static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
{
int ret, skipped, resumed;
- const char *optstring2 = optstring + 1;
if (!optind || __optreset) {
__optreset = 0;
__optpos = 0;
if (argv[i][0] == '-' && argv[i][1]) break;
}
optind = i;
- optstring2 = optstring;
}
resumed = optind;
- ret = __getopt_long_core(argc, argv, optstring2, longopts, idx, longonly);
+ ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
if (resumed > skipped) {
int i, cnt = optind-resumed;
for (i=0; i<cnt; i++)
((longonly && argv[optind][1]) ||
(argv[optind][1] == '-' && argv[optind][2])))
{
+ int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':';
int i, cnt, match;
char *opt;
for (cnt=i=0; longopts[i].name; i++) {
optopt = longopts[i].val;
if (*opt == '=') {
if (!longopts[i].has_arg) {
- if (optstring[0] == ':' || !opterr)
+ if (colon || !opterr)
return '?';
__getopt_msg(argv[0],
": option does not take an argument: ",
} else {
if (longopts[i].has_arg == required_argument) {
if (!(optarg = argv[optind])) {
- if (optstring[0] == ':' || !opterr)
- return ':';
+ if (colon) return ':';
+ if (!opterr) return '?';
__getopt_msg(argv[0],
": option requires an argument: ",
longopts[i].name,
return longopts[i].val;
}
if (argv[optind][1] == '-') {
- if (optstring[0] != ':' && opterr)
+ if (!colon && opterr)
__getopt_msg(argv[0], cnt ?
": option is ambiguous: " :
": unrecognized option: ",