mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] getopt: Add support for '--' to stop option parsing
Date: Mon, 25 Jul 2016 10:32:51 +0200	[thread overview]
Message-ID: <1469435571-31279-1-git-send-email-s.hauer@pengutronix.de> (raw)

In some cases when commands have optional arguments it is necessary
to explicitly stop option parsing after the last nonpositonal option.
Add support for '--' to accomplish this as done in getopt(3) aswell.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/getopt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/getopt.c b/lib/getopt.c
index fd12a88..847830c 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -64,6 +64,11 @@ int getopt(int argc, char *argv[], const char *optstring)
 	while(1) {
 		debug("optindex: %d nonopts: %d optind: %d\n", optindex, nonopts, optind);
 
+		if (optindex == 1 && argv[optind] && !strcmp(argv[optind], "--")) {
+			optind++;
+			return -1;
+		}
+
 		/* first put nonopts to the end */
 		while (optind + nonopts < argc && *argv[optind] != '-') {
 			int i;
-- 
2.8.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2016-07-25  8:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1469435571-31279-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox