Resetting getopt

Rob Landley rob at landley.net
Fri Jul 7 01:33:38 UTC 2006


On Thursday 06 July 2006 7:49 pm, 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
> 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.

Resetting it to 0 should be fine.  Any applet that depends on the value of 
optind before calling getopt is buggy.

Rob
-- 
Never bet against the cheap plastic solution.



More information about the busybox mailing list