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

Sean Hefty sean.hefty at intel.com
Tue Feb 24 20:17:25 PST 2009


>All I'm saying is, if you choose the '?' return value for getopt, then you need
>to fix existing code.

Can you be more specific as to what code breaks and how (what args usage causes
issues)?

I was just trying to understand what the current code is doing to see if my
change would break anything.  It looks like the current code returns optarg as
NULL in the case where the user indicated that an argument is required.  If this
assessment is correct, then it's not obvious to me what code would break.

>Dumps whitespace prior to returning optarg; I did find this when fixing cmd-
>line arg processing of perftests\*; try '-h <sp><sp>arg'. I'm sure there's
>another place where the whitespace dump loop could be moved to.

argv[] should already be whitespace free.  I was trying to guess why the while()
loop might have been needed at one point.  If optarg were set to:

optarg = argv[optind][2];  // the first character after the option

Then optarg could be pointing to a space, in which case a loop is needed to find
the first non-space character.  However, since optarg is set to
argv[some_value], it already points to the start of a string that is whitespace
free.  Soo... my guess is that the while loop looks like a fix that was
superseded by the change in the line immediately above it, which makes it no
longer necessary.  I will remove it when I submit the getopt.c 'fixes'
separately from the const changes.

- Sean




More information about the ofw mailing list