X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fmisc%2Fgetopt_long.c;h=6949ab1c7eec09753b49946da4ceeef6b89e3adc;hb=da845d52c5a8bee206fae899654e393d725a287f;hp=ffbcd42370ab31d857f2e16e7eb0dc11fe975859;hpb=699d4532f6a8f792271c7f46608e2505ca3afc21;p=musl diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index ffbcd423..6949ab1c 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -1,8 +1,11 @@ #define _GNU_SOURCE #include +#include +#include #include #include #include +#include "stdio_impl.h" extern int __optpos, __optreset; @@ -16,8 +19,6 @@ static void permute(char *const *argv, int dest, int src) av[dest] = tmp; } -void __getopt_msg(const char *, const char *, const char *, size_t); - static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly); static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) @@ -51,20 +52,22 @@ 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]) || + ((longonly && argv[optind][1] && argv[optind][1] != '-') || (argv[optind][1] == '-' && argv[optind][2]))) { int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':'; int i, cnt, match; - char *opt; + char *arg, *opt, *start = argv[optind]+1; for (cnt=i=0; longopts[i].name; i++) { const char *name = longopts[i].name; - opt = argv[optind]+1; + opt = start; if (*opt == '-') opt++; - for (; *name && *name == *opt; name++, opt++); + while (*opt && *opt != '=' && *opt == *name) + name++, opt++; if (*opt && *opt != '=') continue; + arg = opt; match = i; if (!*name) { cnt = 1; @@ -72,12 +75,24 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring } cnt++; } + if (cnt==1 && longonly && arg-start == mblen(start, MB_LEN_MAX)) { + int l = arg-start; + for (i=0; optstring[i]; i++) { + int j; + for (j=0; j