This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug argparse/23157] getopt fails when setting optind=1 under some circumstances
- From: "ms at mcdev dot com.au" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Tue, 15 May 2018 00:08:34 +0000
- Subject: [Bug argparse/23157] getopt fails when setting optind=1 under some circumstances
- Auto-submitted: auto-generated
- References: <bug-23157-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=23157
--- Comment #2 from Martin Sandiford <ms at mcdev dot com.au> ---
(In reply to Adhemerval Zanella from comment #1)
> So if you set 'optint' to 0 in the example provided it will pass on GLIBC.
> Unfortunately this is not documented on the manual, only on man-pages [3]
> (on NOTES).
Sure, that's understood.
However, the NOTES section from the referenced Linux man page states:
> NOTES
> A program that scans multiple argument vectors, or rescans the same
> vector more than once, and wants to make use of GNU extensions such
> as '+' and '-' at the start of optstring, or changes the value of
> POSIXLY_CORRECT between scans, must reinitialize getopt() by
> resetting optind to 0, rather than the traditional value of 1.
> (Resetting to 0 forces the invocation of an internal initialization
> routine that rechecks POSIXLY_CORRECT and checks for GNU extensions
> in optstring.)
Which suggests that setting optind to 1 should operate "correctly" when a
program neither uses GNU extensions nor changes POSIXLY_CORRECT.
--
You are receiving this mail because:
You are on the CC list for the bug.