* libc/getopt.c (getopt_internal): Set optreset according to optind
setting earlier. Reevaluate POSIXLY_CORRECT if optreset is set to !0. Handle a leading '-' in options independently of posixly_correct.
This commit is contained in:
parent
cfc4fc9deb
commit
5d5594597e
|
@ -1,3 +1,9 @@
|
|||
2009-12-14 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* libc/getopt.c (getopt_internal): Set optreset according to optind
|
||||
setting earlier. Reevaluate POSIXLY_CORRECT if optreset is set to !0.
|
||||
Handle a leading '-' in options independently of posixly_correct.
|
||||
|
||||
2009-12-09 Christopher Faylor <me+cygwin@cgf.cx>
|
||||
|
||||
* fhandler_fifo.cc (fhandler_fifo::open): Avoid resetting errno after
|
||||
|
|
|
@ -303,19 +303,6 @@ getopt_internal(int nargc, char * const *nargv, const char *options,
|
|||
if (options == NULL)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* Disable GNU extensions if POSIXLY_CORRECT is set or options
|
||||
* string begins with a '+'.
|
||||
*/
|
||||
if (posixly_correct == -1)
|
||||
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
|
||||
if (posixly_correct || *options == '+')
|
||||
flags &= ~FLAG_PERMUTE;
|
||||
else if (*options == '-')
|
||||
flags |= FLAG_ALLARGS;
|
||||
if (*options == '+' || *options == '-')
|
||||
options++;
|
||||
|
||||
/*
|
||||
* XXX Some GNU programs (like cvs) set optind to 0 instead of
|
||||
* XXX using optreset. Work around this braindamage.
|
||||
|
@ -323,6 +310,22 @@ getopt_internal(int nargc, char * const *nargv, const char *options,
|
|||
if (optind == 0)
|
||||
optind = optreset = 1;
|
||||
|
||||
/*
|
||||
* Disable GNU extensions if POSIXLY_CORRECT is set or options
|
||||
* string begins with a '+'.
|
||||
*
|
||||
* CV, 2009-12-14: Check POSIXLY_CORRECT anew if optind == 0 or
|
||||
* optreset != 0 for GNU compatibility.
|
||||
*/
|
||||
if (posixly_correct == -1 || optreset != 0)
|
||||
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
|
||||
if (*options == '-')
|
||||
flags |= FLAG_ALLARGS;
|
||||
else if (posixly_correct || *options == '+')
|
||||
flags &= ~FLAG_PERMUTE;
|
||||
if (*options == '+' || *options == '-')
|
||||
options++;
|
||||
|
||||
optarg = NULL;
|
||||
if (optreset)
|
||||
nonopt_start = nonopt_end = -1;
|
||||
|
|
Loading…
Reference in New Issue