BUG: getopt does not permute argv correctly
Corinna Vinschen
vinschen@redhat.com
Tue May 29 14:14:00 GMT 2018
On May 29 08:08, Joel Sherrill wrote:
> On Tue, May 29, 2018, 7:51 AM Thomas Kindler <mail+newlib@t-kindler.de>
> wrote:
>
> > Thanks for your quick answer!
> >
> > The problem is, that permute_from and num_nonopts is forgotten between
> > calls, if there is more than one option flag in an argv entry.
> >
> > As a solution, I made those variables global, and added them to
> > getopt_data (similar to the existing optwhere).
> >
> >
> > Is there a place or framework for unit tests in newlib?
> >
> >
> > 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.
Keeping the code reentrant is a requirement.
> >
> > 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.
If somebody is really interested to create a unified getopt source for
newlib and Cygwin, it should be a restart from scratch, using the latest
BSD sources. Even if Cygwin's version is newer and, presumably, better
tested, it's still pretty old code. Pulling in reentrancy and the few
Cygwin-specific changes shouldn't be too hard.
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20180529/8d2d44ab/attachment.sig>
More information about the Newlib
mailing list