X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmisc%2Fgetopt_long.c;h=480c00139e08682fd15d5798d871be4c85111b76;hb=cb1875eb4ff755fe6c5d1909f64fc4be1ee396ab;hp=ffbcd42370ab31d857f2e16e7eb0dc11fe975859;hpb=699d4532f6a8f792271c7f46608e2505ca3afc21;p=musl diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index ffbcd423..480c0013 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -51,7 +51,7 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) { - + optarg = 0; if (longopts && argv[optind][0] == '-' && ((longonly && argv[optind][1]) || (argv[optind][1] == '-' && argv[optind][2]))) @@ -87,19 +87,17 @@ 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])) { + 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) {