The different behavior of getopt and optind
H . J . Lu
hjl@valinux.com
Wed Jul 19 16:18:00 GMT 2000
On Wed, Jul 19, 2000 at 02:56:23PM -0700, H . J . Lu wrote:
> Hi, Ulrich,
>
> I got this bug report. I saw
>
> revision 1.26
> date: 1997/04/07 00:45:52; author: drepper; state: Exp; lines: +4 -3
> (_getopt_internal): Preserve optind.
> (_getopt_internal): Set optind to 1 if optind == 0 before
> calling _getopt_initialize ().
>
> in CVS log. Will this change break anything?
>
> Thanks.
>
>
> H.J.
> ---
> Index: posix/getopt.c
> ===================================================================
> RCS file: /work/cvs/gnu/glibc/posix/getopt.c,v
> retrieving revision 1.1.1.1
> diff -u -p -r1.1.1.1 getopt.c
> --- posix/getopt.c 2000/05/21 21:11:20 1.1.1.1
> +++ posix/getopt.c 2000/07/19 21:50:06
> @@ -526,10 +526,9 @@ _getopt_internal (argc, argv, optstring,
>
> optarg = NULL;
>
> - if (optind == 0 || !__getopt_initialized)
> + if (!__getopt_initialized)
> {
> - if (optind == 0)
> - optind = 1; /* Don't scan ARGV[0], the program name. */
> + optind = 1;
> optstring = _getopt_initialize (argc, argv, optstring);
> __getopt_initialized = 1;
> }
>
>
It won't work. We use optind == 0 to tell getopt to reinitialize
itself. Many packages depend on that.
H.J.
More information about the Libc-hacker
mailing list