From 5d5594597eaccccd24e3ee3d07dfdae01c3f89b3 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Mon, 14 Dec 2009 10:47:25 +0000 Subject: * 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. --- winsup/cygwin/libc/getopt.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'winsup/cygwin/libc') diff --git a/winsup/cygwin/libc/getopt.c b/winsup/cygwin/libc/getopt.c index ccec9b512..bc35f96d4 100644 --- a/winsup/cygwin/libc/getopt.c +++ b/winsup/cygwin/libc/getopt.c @@ -303,26 +303,29 @@ getopt_internal(int nargc, char * const *nargv, const char *options, if (options == NULL) return (-1); + /* + * XXX Some GNU programs (like cvs) set optind to 0 instead of + * XXX using optreset. Work around this braindamage. + */ + 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) + if (posixly_correct == -1 || optreset != 0) posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); - if (posixly_correct || *options == '+') - flags &= ~FLAG_PERMUTE; - else if (*options == '-') + if (*options == '-') flags |= FLAG_ALLARGS; + else if (posixly_correct || *options == '+') + flags &= ~FLAG_PERMUTE; if (*options == '+' || *options == '-') options++; - /* - * XXX Some GNU programs (like cvs) set optind to 0 instead of - * XXX using optreset. Work around this braindamage. - */ - if (optind == 0) - optind = optreset = 1; - optarg = NULL; if (optreset) nonopt_start = nonopt_end = -1; -- cgit v1.2.3