getopt reinvocation/reentrancy

Joel Sherrill joel.sherrill@oarcorp.com
Tue Mar 4 02:27:00 GMT 2008


Jeff Johnston wrote:
> Resending as I hit the text/html button accidentally and sourceware
> bounced it.  Also I have changed the content slightly.
>
> Ralf Corsepius wrote:
>   
>> On Thu, 2008-02-28 at 19:21 -0500, Gregory Pietsch wrote:
>>
>>     
>>> I believe that I caught the problem. In your test program, the -a and -b
>>> switches weren't defined in your list of short options, so getopt was
>>> returning a question mark. Fixing the testing program and applying the
>>> latest Bug-Free(tm) getopt should work. -- Gregory
>>>
>>>       
>> I think, some defines, you added to getopt.h with your most recent patch
>> should be removed. In particular:
>>
>> /* macros defined by this include file */
>> #define NO_ARG                  0
>> #define REQUIRED_ARG            1
>> #define OPTIONAL_ARG            2
>>   /* The GETOPT_DATA_INITIALIZER macro is used to initialize a
>> statically-
>>      allocated variable of type struct getopt_data.  */
>> #define GETOPT_DATA_INITIALIZER {0,0,0,0,0}
>>
>> Rationale:
>>
>> - The *_ARG macros are not name-space safe and likely to clash with
>> other macros. If they really should be kept, then they should be
>> prefixed with __GETOPT_.
>>
>> - All of these macros are not standardized anywhere nor am I aware about
>> any system providing them. I vote for removing them.
>>
>>
>>     
> To be fair, the header file itself is non-standard; it is a glibc
> extension and any application that includes it will expect at least some
> non-clean macros since the glibc version of <getopt.h> declares struct
> option, includes 3 macros: no_argument, required_argument,
> optional_argument that are unprotected and adds the functions
> getopt_long and getopt_long_only.  The sys/linux version of getopt.h
> defines the 3 glibc macros for compatibility and so should the
> libc/include version.  I'd be happy with only having the glibc names.
> We could also optionally add a single underscore to the initializer
> macro and two underscores to the special struct added for reentrancy to
> make us essentially namespace-clean-equivalent to the glibc version.
> Joel, as one of probably few getopt.h/getopt users, what do you think of
> removing the old argument macros?
>   

It doesn't bother me at all.  All I wanted was the functionality
of being able to reparse a set of argc/argv arguments within
a single executable.

If we end up more compatible with the current glibc, then
so much the better.

--joel
> I have just added the glibc macros to getopt.h.
>
> -- Jeff J.
>
>
>   


-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
   Support Available             (256) 722-9985




More information about the Newlib mailing list