Resetting getopt

Peter S. Mazinger ps.m at gmx.net
Fri Jul 7 00:45:39 PDT 2006


On Thu, 6 Jul 2006, Shaun Jackman wrote:

> There seems to be a bug in every applet -- mostly shells -- that
> attempt to reset getopt. They all set `optind = 1;', but the getopt

from the glibc getopt.c:
/* 1003.2 says this must be 1 before any call */
int optind = 1;

Peter

> implementations I've read (uClibc and newlib) use the test `if (optind
> == 0)' to reset the getopt internals. Specifically, the static pointer
> that iterates through short options needs resetting. I'd recommended
> changing all the occurrences of `optind = 1;' to `optind = 0;'. Any
> thoughts of any complications this could cause? The only one I can
> think of is a possibly errant applet that depends on optind == 1
> *before* getopt is called. All will be fine after getopt is called for
> the first time.
> 
> Cheers,
> Shaun
> 
> 

-- 
Peter S. Mazinger <ps dot m at gmx dot net>           ID: 0xA5F059F2
Key fingerprint = 92A4 31E1 56BC 3D5A 2D08  BB6E C389 975E A5F0 59F2



More information about the busybox mailing list