Loading...
--- Libc/Libc-1725.40.4/stdlib/FreeBSD/getopt_long.c
+++ Libc/Libc-763.11/stdlib/FreeBSD/getopt_long.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */
+/* $OpenBSD: getopt_long.c,v 1.21 2006/09/22 17:22:05 millert Exp $ */
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
/*
@@ -35,6 +35,13 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -55,7 +62,7 @@
#endif /* LIBC_SCCS and not lint */
#endif
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/getopt_long.c,v 1.15 2006/09/23 14:48:31 ache Exp $");
#include <err.h>
#include <errno.h>
@@ -88,7 +95,7 @@
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
#define INORDER (int)1
-static char EMSG[] = "";
+#define EMSG ""
#ifdef GNU_COMPATIBLE
#define NO_PREFIX (-1)
@@ -194,7 +201,7 @@
{
char *current_argv, *has_equal;
#ifdef GNU_COMPATIBLE
- const char *current_dash;
+ char *current_dash;
#endif
size_t current_argv_len;
int i, match, exact_match, second_partial_match;
@@ -248,7 +255,7 @@
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,10 +366,29 @@
{
char *oli; /* option letter list index */
int optchar, short_too;
- static int posixly_correct = -1;
+ int posixly_correct; /* no static, can be changed on the fly */
if (options == NULL)
return (-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 (*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
@@ -370,19 +396,6 @@
*/
if (optind == 0)
optind = optreset = 1;
-
- /*
- * Disable GNU extensions if POSIXLY_CORRECT is set or options
- * string begins with a '+'.
- */
- if (posixly_correct == -1 || optreset)
- 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)
@@ -481,8 +494,6 @@
#endif
if (*place == '-') {
place++; /* --foo long option */
- if (*place == '\0')
- return (BADARG); /* malformed option */
#ifdef GNU_COMPATIBLE
dash_prefix = DD_PREFIX;
#endif