diff options
author | kfogel <kfogel@13f79535-47bb-0310-9956-ffa450edef68> | 2000-11-25 05:14:59 +0000 |
---|---|---|
committer | kfogel <kfogel@13f79535-47bb-0310-9956-ffa450edef68> | 2000-11-25 05:14:59 +0000 |
commit | 154f051f1cc08c1071f7337f5132c72769cf2bf6 (patch) | |
tree | fbdc3f260570e81d5204aed57e663140335158fc /misc | |
parent | 0c3f6862ea28593792e2811894210ae1ed804fd5 (diff) | |
download | libapr-154f051f1cc08c1071f7337f5132c72769cf2bf6.tar.gz |
More changes from Greg Hudson <ghudson@mit.edu>, w/ small doc tweaks
from Karl Fogel <kfogel@collab.net>:
(apr_getopt_option_t): rename from apr_longopt_t, because more accurate.
(apr_initopt, apr_getopt_long, reverse): take "char *const *argv", act
on a copy instead of the original, since we may permute the array.
This is a compromise. The parameter must be compatible with the argv
value passed to main, since that is the primary purpose of the
function. But as has been pointed out, people might want to use the
function with arrays other than argv, and we shouldn't touch the
caller's data.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@60790 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r-- | misc/unix/getopt.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/misc/unix/getopt.c b/misc/unix/getopt.c index 5353dd89f..e31a62106 100644 --- a/misc/unix/getopt.c +++ b/misc/unix/getopt.c @@ -49,14 +49,24 @@ static const char *pretty_path (const char *name) } APR_DECLARE(apr_status_t) apr_initopt(apr_getopt_t **os, apr_pool_t *cont, - int argc, char **argv) + int argc, char *const *argv) { + int i; + *os = apr_palloc(cont, sizeof(apr_getopt_t)); (*os)->cont = cont; (*os)->err = 1; (*os)->place = EMSG; (*os)->argc = argc; - (*os)->argv = argv; + + /* The argv parameter must be compatible with main()'s argv, since + that's the primary purpose of this function. But people might + want to use this function with arrays other than the main argv, + and we shouldn't touch the caller's data. So we copy. */ + (*os)->argv = apr_palloc(cont, argc * sizeof(const char *)); + for (i = 0; i < argc; i++) + (*os)->argv[i] = argv[i]; + (*os)->interleave = 0; (*os)->ind = 1; (*os)->skip_start = 1; @@ -135,9 +145,9 @@ APR_DECLARE(apr_status_t) apr_getopt(apr_getopt_t *os, const char *opts, } /* Reverse the sequence argv[start..start+len-1]. */ -static void reverse(char **argv, int start, int len) +static void reverse(const char **argv, int start, int len) { - char *temp; + const char *temp; for (; len >= 2; start++, len -= 2) { temp = argv[start]; @@ -193,7 +203,7 @@ static apr_status_t cerr(apr_getopt_t *os, const char *err, int ch, } APR_DECLARE(apr_status_t) apr_getopt_long(apr_getopt_t *os, - const apr_longopt_t *opts, + const apr_getopt_option_t *opts, int *optch, const char **optarg) { const char *p; |