mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: musl@lists.openwall.com
Cc: Samuel Holland <samuel@sholland.org>
Subject: [PATCH 2/2] support long options containing equals signs
Date: Mon, 29 Jan 2018 20:36:42 -0600	[thread overview]
Message-ID: <20180130023642.2363-2-samuel@sholland.org> (raw)
In-Reply-To: <20180130023642.2363-1-samuel@sholland.org>

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



      reply	other threads:[~2018-01-30  2:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-30  2:36 [PATCH 1/2] fix getopt_long arguments to partial matches Samuel Holland
2018-01-30  2:36 ` Samuel Holland [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180130023642.2363-2-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).