From 91184c4f16b143107fa9935edebe5d2b20bd70d8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 20 Dec 2014 19:44:37 -0500 Subject: add error message printing to getopt_long and make related improvements some related changes are also made to getopt, and the return value of getopt_long in the case of missing arguments is fixed. --- src/misc/getopt_long.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'src/misc/getopt_long.c') diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index df2083bb..45992f85 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -2,6 +2,7 @@ #include #include #include +#include extern int __optpos, __optreset; @@ -15,11 +16,14 @@ static void permute(char *const *argv, int dest, int src) av[dest] = tmp; } +void __getopt_msg(const char *, const char *, const char *, size_t); + static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly); static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) { int ret, skipped, resumed; + const char *optstring2 = optstring + 1; if (!optind || __optreset) { __optreset = 0; __optpos = 0; @@ -34,9 +38,10 @@ static int __getopt_long(int argc, char *const *argv, const char *optstring, con if (argv[i][0] == '-' && argv[i][1]) break; } optind = i; + optstring2 = optstring; } resumed = optind; - ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly); + ret = __getopt_long_core(argc, argv, optstring2, longopts, idx, longonly); if (resumed > skipped) { int i, cnt = optind-resumed; for (i=0; i