mailing list of musl libc
 help / color / mirror / code / Atom feed
* [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

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).