[ofw] [PATCH] getopt: add use of const to interface
Smith, Stan
stan.smith at intel.com
Tue Feb 24 12:38:36 PST 2009
Hi Sean,
Please verify correct operation of trunk\tests\perftest\rdma_bw\rdma_bw.c + rdma_lat.c, there may be more. For "case 'h':" I faintly recollect the
> - optarg = NULL;
in getopt.c was critical for correct parsing of cmd-line arguments.
The NULL optarg seems to be required, please fix what you consider to be broken.
Either (optarg != '?') or (optarg); your call.
Thanks,
Stan.
Sean Hefty wrote:
> Add const to getopt argv argument, and allow getopt to be included by
> c++.
>
> This allows the ib-diags to call getopt without build warnings.
>
> Signed-off-by: Sean Hefty <sean.hefty at intel.com>
> ---
> I will commit this to the trunk unless there are concerns.
>
> diff -up -r -X trunk\docs\dontdiff.txt -I '\$Id:'
> trunk\etc\user/getopt.c branches\winverbs\etc\user/getopt.c ---
> trunk\etc\user/getopt.c 2009-02-11 05:28:36.399500000 -0800 +++
> branches\winverbs\etc\user/getopt.c 2009-02-12 17:22:01.255925600
> -0800 @@ -39,7 +39,7 @@ int optind = 1; int opterr = 1;
> int optopt = '?';
>
> -int getopt(int argc, char **argv, char const *opts)
> +int getopt(int argc, char * const argv[], char const *opts)
> {
> char *loc;
>
> @@ -79,16 +79,20 @@ int getopt(int argc, char **argv, char c
> goto out;
>
> optarg = argv[++optind];
> - while(optarg && *optarg && (*optarg == ' ' || *optarg == ' '))
> optarg++;
> - if (optarg && !(*optarg))
> - optarg = NULL;
> + while(optarg && *optarg && (*optarg == ' ' || *optarg == ' ')) {
> + optarg++;
> + }
> +
> + if (!optarg || !(*optarg)) {
> + return '?';
> + }
>
> out:
> optind++;
> return optopt;
> }
>
> -int getopt_long(int argc, char **argv, char const *opts,
> +int getopt_long(int argc, char * const argv[], char const *opts,
> const struct option *longopts, int *longindex)
> {
> char arg[256];
> --- trunk\inc\user\getopt.h 2009-02-11 05:28:36.274500000 -0800
> +++ branches\winverbs\inc\user\getopt.h 2009-02-12 17:21:41.368737700
> -0800 @@ -31,6 +31,11 @@
> #ifndef _GETOPT_H_
> #define _GETOPT_H_
>
> +#ifdef __cplusplus
> +extern "C"
> +{
> +#endif
> +
> extern char *optarg;
> extern int optind;
> extern int opterr;
> @@ -51,8 +56,12 @@ enum
> optional_argument
> };
>
> -extern int getopt(int argc, char **argv, char const *opts);
> -extern int getopt_long(int argc, char **argv, char const *opts,
> +extern int getopt(int argc, char * const argv[], char const *opts);
> +extern int getopt_long(int argc, char * const argv[], char const
> *opts, const struct option *longopts, int *longindex);
>
> +#ifdef __cplusplus
> +} // extern "C"
> +#endif
> +
> #endif
>
> _______________________________________________
> ofw mailing list
> ofw at lists.openfabrics.org
> http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ofw
More information about the ofw
mailing list