getopt: handle non-long --foo like glibc does

This commit is contained in:
K. Lange 2018-09-07 10:19:14 +09:00
parent b99b17c967
commit ee34f63d55

View File

@ -32,11 +32,7 @@ int getopt_long(int argc, char * const argv[], const char *optstring, const stru
/* End of arguments */
optind++;
return -1;
} else {
if (!longopts) {
optind++;
return -1;
}
} else if (longopts) {
/* Scan through options */
nextchar++;
char tmp[strlen(nextchar)+1];
@ -87,6 +83,7 @@ int getopt_long(int argc, char * const argv[], const char *optstring, const stru
}
}
}
/* else: --foo but not long, see if -: is set, otherwise continue as if - was an option */
}
}
}
@ -97,7 +94,7 @@ int getopt_long(int argc, char * const argv[], const char *optstring, const stru
continue;
}
if ((*nextchar < 'A' || *nextchar > 'z' || (*nextchar > 'Z' && *nextchar < 'a')) && (*nextchar != '?')) {
if ((*nextchar < 'A' || *nextchar > 'z' || (*nextchar > 'Z' && *nextchar < 'a')) && (*nextchar != '?') && (*nextchar != '-')) {
if (opterr) {
fprintf(stderr, "Invalid option character: %c\n", *nextchar);
}