diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-07-21 14:38:24 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-07-25 10:30:19 +0200 |
commit | 70460e9723acb8547f688930a41f0a941fd8796b (patch) | |
tree | 0288dc6f0ac036f1c4b519da201389d2a956810c /lib/getopt.c | |
parent | a435c13e8809a5f92496fcbae3a38b7609cad515 (diff) | |
download | barebox-70460e9723acb8547f688930a41f0a941fd8796b.tar.gz barebox-70460e9723acb8547f688930a41f0a941fd8796b.tar.xz |
getopt: Add support for '--' to stop option parsing
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>
Diffstat (limited to 'lib/getopt.c')
-rw-r--r-- | lib/getopt.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/getopt.c b/lib/getopt.c index fd12a886ec..847830c22b 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; |