X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmisc%2Fgetopt_long.c;h=568ae7ba9dac991eda343bcd2ab2e30371309dff;hb=bd00cc87819875882356298b6c6bdabc1700753f;hp=bee77f43c9acbca9a0dd7f0fa49eb4113af99e70;hpb=e8e4e56a8ce1f3d7e4a027ff5478f2f8ea70c46b;p=musl diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index bee77f43..568ae7ba 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -53,7 +53,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring { optarg = 0; if (longopts && argv[optind][0] == '-' && - ((longonly && argv[optind][1]) || + ((longonly && argv[optind][1] && argv[optind][1] != '-') || (argv[optind][1] == '-' && argv[optind][2]))) { int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':'; @@ -75,9 +75,9 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring if (cnt==1) { i = match; optind++; - optopt = longopts[i].val; if (*opt == '=') { if (!longopts[i].has_arg) { + optopt = longopts[i].val; if (colon || !opterr) return '?'; __getopt_msg(argv[0], @@ -87,19 +87,18 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring return '?'; } optarg = opt+1; - } else { - if (longopts[i].has_arg == required_argument) { - if (!(optarg = argv[optind])) { - if (colon) return ':'; - if (!opterr) return '?'; - __getopt_msg(argv[0], - ": option requires an argument: ", - longopts[i].name, - strlen(longopts[i].name)); - return '?'; - } - optind++; - } else optarg = NULL; + } else if (longopts[i].has_arg == required_argument) { + if (!(optarg = argv[optind])) { + optopt = longopts[i].val; + if (colon) return ':'; + if (!opterr) return '?'; + __getopt_msg(argv[0], + ": option requires an argument: ", + longopts[i].name, + strlen(longopts[i].name)); + return '?'; + } + optind++; } if (idx) *idx = i; if (longopts[i].flag) { @@ -109,6 +108,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring return longopts[i].val; } if (argv[optind][1] == '-') { + optopt = 0; if (!colon && opterr) __getopt_msg(argv[0], cnt ? ": option is ambiguous: " :