X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Fopt.c;h=ea27dfa7679f2c8a6e8353558ceec5eff3297e49;hp=155d7aaf46b64c93ca712f550521f6e4e6aa423f;hb=b4cf10d83d46b50468ae52fccaeb99a793505467;hpb=d89e5744f30b584ac4909ce1164af1289c41359b diff --git a/ccan/opt/opt.c b/ccan/opt/opt.c index 155d7aaf..ea27dfa7 100644 --- a/ccan/opt/opt.c +++ b/ccan/opt/opt.c @@ -280,7 +280,6 @@ bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...)) != -1) { char *problem; const char *name; - bool missing = false; /* optopt is 0 if it's an unknown long option, *or* if * -? is a valid short option. */ @@ -291,8 +290,10 @@ bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...)) break; } } else if (ret == ':') { - missing = true; - ret = optopt; + /* Missing argument: longidx not updated :( */ + parse_fail(errlog, optopt, argv[optind-1]+2, + "option requires an argument"); + break; } if (ret != 0) @@ -300,13 +301,6 @@ bool opt_parse(int *argc, char *argv[], void (*errlog)(const char *fmt, ...)) else e = find_long(longidx, &name); - /* Missing argument */ - if (missing) { - parse_fail(errlog, ret, name, - "option requires an argument"); - break; - } - if (e->flags == OPT_HASARG) problem = e->cb_arg(optarg, e->arg); else