apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karl Fogel <kfo...@galois.collab.net>
Subject Re: [PATCH] add another const to apr_initopt()
Date Sun, 26 Nov 2000 23:33:39 GMT
Greg Stein <gstein@lyra.org> writes:
> Since there seems to be a couple minds on this last bit of const work, I'm
> posting this patch (inline, below) rather than applying it. See my other
> note for why I believe that we need this.
> 
> Any reasons not to apply?

+1.  We're copying the array anyway, so might as well make the param
as const as we possibly can. :-)

-K


> [ I'll wait until Monday, after the holiday ]
> 
> Cheers,
> -g
> 
> -- 
> Greg Stein, http://www.lyra.org/
> 
> Index: include/apr_getopt.h
> ===================================================================
> RCS file: /home/cvs/apr/include/apr_getopt.h,v
> retrieving revision 1.25
> diff -u -r1.25 apr_getopt.h
> --- include/apr_getopt.h	2000/11/25 05:27:39	1.25
> +++ include/apr_getopt.h	2000/11/25 22:22:47
> @@ -108,7 +108,7 @@
>   * @deffunc apr_status_t apr_initopt(apr_getopt_t **os, apr_pool_t *cont,int argc, char
*const *argv)
>   */
>  APR_DECLARE(apr_status_t) apr_initopt(apr_getopt_t **os, apr_pool_t *cont,
> -                                      int argc, char *const *argv);
> +                                      int argc, const char *const *argv);
>  
>  /**
>   * Parse the options initialized by apr_initopt().
> Index: misc/unix/getopt.c
> ===================================================================
> RCS file: /home/cvs/apr/misc/unix/getopt.c,v
> retrieving revision 1.27
> diff -u -r1.27 getopt.c
> --- misc/unix/getopt.c	2000/11/25 05:52:17	1.27
> +++ misc/unix/getopt.c	2000/11/25 22:25:24
> @@ -49,10 +49,8 @@
>  }
>  
>  APR_DECLARE(apr_status_t) apr_initopt(apr_getopt_t **os, apr_pool_t *cont,
> -                                     int argc, char *const *argv)
> +                                      int argc, const char *const *argv)
>  {
> -    int i;
> -
>      *os = apr_palloc(cont, sizeof(apr_getopt_t));
>      (*os)->cont = cont;
>      (*os)->err = 1;
> @@ -64,19 +62,19 @@
>         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 + 1) * sizeof(const char *));
> -    for (i = 0; i < argc; i++)
> -	(*os)->argv[i] = argv[i];
> +    memcpy((*os)->argv, argv, argc * sizeof(const char *));
>      (*os)->argv[argc] = NULL;
>  
>      (*os)->interleave = 0;
>      (*os)->ind = 1;
>      (*os)->skip_start = 1;
>      (*os)->skip_end = 1;
> +
>      return APR_SUCCESS;
>  }
>  
>  APR_DECLARE(apr_status_t) apr_getopt(apr_getopt_t *os, const char *opts, 
> -                                    char *optch, const char **optarg)
> +                                     char *optch, const char **optarg)
>  {
>      const char *oli;  /* option letter list index */
>  
> Index: test/testargs.c
> ===================================================================
> RCS file: /home/cvs/apr/test/testargs.c,v
> retrieving revision 1.16
> diff -u -r1.16 testargs.c
> --- test/testargs.c	2000/11/25 22:34:04	1.16
> +++ test/testargs.c	2000/11/25 22:34:58
> @@ -73,7 +73,7 @@
>      }
>  }
>  
> -int main(int argc, char * const argv[])
> +int main(int argc, const char * const argv[])
>  {
>      apr_pool_t *context;
>      apr_getopt_t *opt;

Mime
View raw message