summaryrefslogtreecommitdiffstats
path: root/libc/upstream-freebsd
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-09-24 12:39:34 -0700
committerElliott Hughes <enh@google.com>2014-09-24 12:39:34 -0700
commitaf12924f673a8c374132a318c88f573116f221cb (patch)
treee5767b97e18ba50ff73834709f003d2bfb77aa93 /libc/upstream-freebsd
parentf05410edc634040f96643b8f378320faddfef423 (diff)
downloadbionic-af12924f673a8c374132a318c88f573116f221cb.zip
bionic-af12924f673a8c374132a318c88f573116f221cb.tar.gz
bionic-af12924f673a8c374132a318c88f573116f221cb.tar.bz2
Sync with current upstream getopt_long.c.
Change-Id: I269195aa581a688fd3eb99552d506b8f5f6a8395
Diffstat (limited to 'libc/upstream-freebsd')
-rw-r--r--libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c30
1 files changed, 12 insertions, 18 deletions
diff --git a/libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c b/libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c
index 9f7f6d5..9534a2a 100644
--- a/libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c
+++ b/libc/upstream-freebsd/lib/libc/stdlib/getopt_long.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getopt_long.c,v 1.22 2006/10/04 21:29:04 jmc Exp $ */
+/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
/*
@@ -248,7 +248,7 @@ parse_long_options(char * const *nargv, const char *options,
if (short_too && current_argv_len == 1)
continue;
- if (match == -1) /* first partial match */
+ if (match == -1) /* first partial match */
match = i;
else if ((flags & FLAG_LONGONLY) ||
long_options[i].has_arg !=
@@ -359,37 +359,31 @@ getopt_internal(int nargc, char * const *nargv, const char *options,
{
char *oli; /* option letter list index */
int optchar, short_too;
- int posixly_correct; /* no static, can be changed on the fly */
+ static int posixly_correct = -1;
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 '+'.
*/
- posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
-#ifdef GNU_COMPATIBLE
+ if (posixly_correct == -1 || optreset)
+ posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
if (*options == '-')
flags |= FLAG_ALLARGS;
else if (posixly_correct || *options == '+')
flags &= ~FLAG_PERMUTE;
-#else
- if (posixly_correct || *options == '+')
- flags &= ~FLAG_PERMUTE;
- else if (*options == '-')
- flags |= FLAG_ALLARGS;
-#endif
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;