[ofw] [PATCH] getopt: add use of const to interface

Sean Hefty sean.hefty at intel.com
Tue Feb 24 12:55:54 PST 2009


>  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

The perftest are working for me, but I'm not sure I'm testing the option that
you're thinking about.

>> -	while(optarg && *optarg && (*optarg == ' ' || *optarg == '	'))
>> optarg++;
>> -	if (optarg && !(*optarg))
>> -		optarg = NULL;
>> +	while(optarg && *optarg && (*optarg == ' ' || *optarg == '	')) {
>> +		optarg++;
>> +	}
>> +
>> +	if (!optarg || !(*optarg)) {
>> +		return '?';
>> +	}

This change should go in separately.  I'll pull this out when committing the
change to add the const.  I added this change to fix the case where an argument
was required, but none was provided.  This shows up if you define the options
like "a:" -- where the last option in the list requires an argument.  With the
current code, if -a is given, but no argument follows, the user is returned a
NULL optarg, which leads to a crash.  (I think this is the case; this fixed a
real bug that I hit anyway.)

- Sean




More information about the ofw mailing list