From 5f73996bf368e7f5d7249679c738a87873cb340d Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 12 Sep 2018 12:14:14 -0700 Subject: fixes #720 fix for #715 still not right The fix for #715 to address const is still not quite right. In ISO C, the argv array is just char **. getopt() in POSIX uses char *const[]. That part is right, but we should then not pass const char ** in calls. Furthermore, really the optarg should also not be constified. This aligns us closer to getopt() and leads to the fewest problems. This does represent a slight breaking change, but as old code should still compile and run, we don't think we should bump the API version for this change. Furthermore, we don't think anyone else is actually using this API yet. --- src/supplemental/util/options.c | 4 ++-- src/supplemental/util/options.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/supplemental/util/options.c b/src/supplemental/util/options.c index c1881185..826a3692 100644 --- a/src/supplemental/util/options.c +++ b/src/supplemental/util/options.c @@ -17,13 +17,13 @@ // Call with optidx set to 1 to start parsing. int nng_opts_parse(int argc, char *const *argv, const nng_optspec *opts, int *val, - const char **optarg, int *optidx) + char **optarg, int *optidx) { const nng_optspec *opt; int matches; bool shortopt; size_t l; - const char * arg = argv[*optidx]; + char * arg = argv[*optidx]; int i; if ((i = *optidx) >= argc) { diff --git a/src/supplemental/util/options.h b/src/supplemental/util/options.h index 392c4a53..83969a90 100644 --- a/src/supplemental/util/options.h +++ b/src/supplemental/util/options.h @@ -39,7 +39,7 @@ typedef struct nng_optspec nng_optspec; // Returns -1 when the end of options is reached, 0 on success, or // NNG_EINVAL if the option parse is invalid for any reason. NNG_DECL int nng_opts_parse(int argc, char *const *argv, - const nng_optspec *opts, int *val, const char **optarg, int *optidx); + const nng_optspec *opts, int *val, char **optarg, int *optidx); #ifdef __cplusplus } -- cgit v1.2.3-70-g09d2