* [PATCH 1/2] fix getopt_long arguments to partial matches
@ 2018-01-30 2:36 Samuel Holland
2018-01-30 2:36 ` [PATCH 2/2] support long options containing equals signs Samuel Holland
0 siblings, 1 reply; 2+ messages in thread
From: Samuel Holland @ 2018-01-30 2:36 UTC (permalink / raw)
To: musl; +Cc: Samuel Holland
If we find a partial option name match, we need to keep looking for
ambiguous/conflicting options. However, we need to remember the position
in the candidate argument to find its option-argument later, if there is
one. This fixes e.g. option "foobar" being given as "--fooba=baz".
---
src/misc/getopt_long.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
index 568ae7ba..0d1501d4 100644
--- a/src/misc/getopt_long.c
+++ b/src/misc/getopt_long.c
@@ -58,13 +58,14 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
{
int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':';
int i, cnt, match;
- char *opt;
+ char *arg, *opt;
for (cnt=i=0; longopts[i].name; i++) {
const char *name = longopts[i].name;
opt = argv[optind]+1;
if (*opt == '-') opt++;
for (; *name && *name == *opt; name++, opt++);
if (*opt && *opt != '=') continue;
+ arg = opt;
match = i;
if (!*name) {
cnt = 1;
@@ -74,6 +75,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
}
if (cnt==1) {
i = match;
+ opt = arg;
optind++;
if (*opt == '=') {
if (!longopts[i].has_arg) {
--
2.13.6
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] support long options containing equals signs
2018-01-30 2:36 [PATCH 1/2] fix getopt_long arguments to partial matches Samuel Holland
@ 2018-01-30 2:36 ` Samuel Holland
0 siblings, 0 replies; 2+ messages in thread
From: Samuel Holland @ 2018-01-30 2:36 UTC (permalink / raw)
To: musl; +Cc: Samuel Holland
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.
---
src/misc/getopt_long.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c
index 0d1501d4..008b747c 100644
--- a/src/misc/getopt_long.c
+++ b/src/misc/getopt_long.c
@@ -63,7 +63,8 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring
const char *name = longopts[i].name;
opt = argv[optind]+1;
if (*opt == '-') opt++;
- for (; *name && *name == *opt; name++, opt++);
+ while (*opt && *opt != '=' && *opt == *name)
+ name++, opt++;
if (*opt && *opt != '=') continue;
arg = opt;
match = i;
--
2.13.6
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-30 2:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-30 2:36 [PATCH 1/2] fix getopt_long arguments to partial matches Samuel Holland
2018-01-30 2:36 ` [PATCH 2/2] support long options containing equals signs Samuel Holland
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).