提交 6f03b61b 编写于 作者: S Samuel Holland 提交者: Rich Felker

getopt_long: accept prefix match of long options containing equals signs

Consider the first equals sign found in the option to be the delimiter
between it and its argument, even if it matches an equals sign in the
option name. This avoids consuming the equals sign, which would prevent
finding the argument. Instead, it forces a partial match of the part of
the option name before the equals sign.

Maintainer's note: GNU getopt_long does not explicitly document this
behavior, but it can be seen as a consequence of how partial matches
are specified, and at least GNU (bfd) ld is known to make use of it.
上级 f1abc29b
...@@ -63,7 +63,8 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring ...@@ -63,7 +63,8 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
const char *name = longopts[i].name; const char *name = longopts[i].name;
opt = argv[optind]+1; opt = argv[optind]+1;
if (*opt == '-') opt++; if (*opt == '-') opt++;
for (; *name && *name == *opt; name++, opt++); while (*opt && *opt != '=' && *opt == *name)
name++, opt++;
if (*opt && *opt != '=') continue; if (*opt && *opt != '=') continue;
arg = opt; arg = opt;
match = i; match = i;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册