This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: BUG: getopt does not permute argv correctly
On Tue, May 29, 2018 15:08, Joel Sherrill wrote:
> On Tue, May 29, 2018, 7:51 AM Thomas Kindler <mail+newlib@t-kindler.de>
> wrote:
>>
>> In the long run, I think it would be best to have only one common
>> getopt in newlib and cygwin. I suspect that very few embedded projects
>> use getopt, and so bugs like this could slip through for some years.
>>
>
> RTEMS uses getopt_r with our shell. Since we are a single process, each
> commands "main" needs its own view of the area and argv processing.
Of course - I also need newlib's getopt_r for use with FreeRTOS.
>>
>> Cygwin's getopt is used and tested much more often, and is about the
>> same in code complexity. Code size reductions, like using fputs()
>> instead of fprintf(), smaller permute(), and reentrant state could be
>> ported relatively easily.
>>
>
> Not disagreeing with you just pointing out that getopt() is only useful
> in a single process embedded system if you only process arguments once.
>
That's what I meant by "reentrant state could be ported relatively easily".
We could take the (hopefully better tested) cygwin/net/openbsd getopt
logic, and patch in read_globals/write_globals functions like in newlib's
existing getopt to get the _r functionality.
best regards,
--
Thomas Kindler