Handle both GNU and BSD getopt reinit

This allows all the tests to pass on systems that use the BSD version of getopt which uses optind = 1 and optreset to reinitialize getopt.