summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/stdlib/getopt_long.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c
index c4f09cb23e8..2eec98530a6 100644
--- a/lib/libc/stdlib/getopt_long.c
+++ b/lib/libc/stdlib/getopt_long.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: getopt_long.c,v 1.7 2002/12/07 19:48:32 millert Exp $ */
+/* $OpenBSD: getopt_long.c,v 1.8 2002/12/08 07:23:09 millert Exp $ */
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
/*
@@ -64,7 +64,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: getopt_long.c,v 1.7 2002/12/07 19:48:32 millert Exp $";
+static char *rcsid = "$OpenBSD: getopt_long.c,v 1.8 2002/12/08 07:23:09 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <err.h>
@@ -348,8 +348,7 @@ start:
nonopt_start = nonopt_end = -1;
return (-1);
}
- if ((*(place = nargv[optind]) != '-')
- || (place[1] == '\0')) { /* found non-option */
+ if (*(place = nargv[optind]) != '-') { /* found non-option */
place = EMSG;
if (flags & FLAG_ALLARGS) {
/*
@@ -383,8 +382,11 @@ start:
if (nonopt_start != -1 && nonopt_end == -1)
nonopt_end = optind;
- /* check for "--" or "--foo" with no long options */
- if (*++place == '-' &&
+ /*
+ * Check for "--" or "--foo" with no long options
+ * but if place is simply "-" leave it unmolested.
+ */
+ if (place[1] != '\0' && *++place == '-' &&
(place[1] == '\0' || long_options == NULL)) {
optind++;
place = EMSG;
@@ -402,8 +404,13 @@ start:
}
}
- /* check long options if we have any */
- if (long_options != NULL &&
+ /*
+ * Check long options if:
+ * 1) we were passed some
+ * 2) the arg is not just "-"
+ * 3) either the arg starts with -- we are getopt_long_only()
+ */
+ if (long_options != NULL && place != nargv[optind] &&
(*place == '-' || (flags & FLAG_LONGONLY))) {
short_too = 0;
if (*place == '-')