From 36edef5d6b4748bd86575208e7edcffeb124b74f Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 7 Jan 2017 09:43:10 -0500 Subject: [PATCH] getopt_long(): record successful completed parsing of all arguments. --- src/misc/getopt_long.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index 568ae7b..5ff0e37 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -5,6 +5,7 @@ #include extern int __optpos, __optreset; +static int __getopt_yay = 0; static void permute(char *const *argv, int dest, int src) { @@ -26,8 +27,13 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con if (!optind || __optreset) { __optreset = 0; __optpos = 0; + __getopt_yay = 0; optind = 1; } + if (optind == argc && __getopt_yay) { + optopt = 0; + return -1; + } if (optind >= argc || !argv[optind]) return -1; skipped = optind; if (optstring[0] != '+' && optstring[0] != '-') { @@ -46,6 +52,8 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con permute(argv, skipped, optind-1); optind = skipped + cnt; } + if ((ret != '?') && (ret != ':')) + __getopt_yay = (optind == argc); return ret; } -- 2.8.3