Resetting getopt

Shaun Jackman sjackman at gmail.com
Thu Jul 6 23:49:54 UTC 2006


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.

Cheers,
Shaun



More information about the busybox mailing list