diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-02-04 18:17:26 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-02-04 18:17:26 +0000 |
commit | ed85d8ab18019201fd2e1d3afaeb0f91a6272af9 (patch) | |
tree | 04b8137ea6ddff57ddf4434d8d51f83267e66209 /lib | |
parent | 4e2061a4b1e18d25f4df574db32637ba7b497d15 (diff) |
Traditionally, getopt(3) has treated "--foo" the same as "--". However,
this can cause confusion when a user tries to use a long option with
a program that only supports short options. Furthermore, it appears
to be in violation of POSIX, which states that "--" shall indicate
the end of argument processing, not any string that begins with "--".
OK otto@ and closes PR 3666.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdlib/getopt_long.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c index 1f7f5baa8b5..6079ce35030 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.15 2003/09/22 23:45:22 millert Exp $ */ +/* $OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $ */ /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ /* @@ -57,7 +57,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: getopt_long.c,v 1.15 2003/09/22 23:45:22 millert Exp $"; +static char *rcsid = "$OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <err.h> @@ -379,11 +379,9 @@ start: nonopt_end = optind; /* - * Check for "--" or "--foo" with no long options - * but if place is simply "-" leave it unmolested. + * If we have "-" do nothing, if "--" we are done. */ - if (place[1] != '\0' && *++place == '-' && - (place[1] == '\0' || long_options == NULL)) { + if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { optind++; place = EMSG; /* @@ -423,14 +421,15 @@ start: } if ((optchar = (int)*place++) == (int)':' || + optchar == (int)'-' && *place != '\0' || (oli = strchr(options, optchar)) == NULL) { /* - * If the user didn't specify '-' as an option, - * assume it means -1 as POSIX specifies. + * If the user specified "-" and '-' isn't listed in + * options, return -1 (non-option) as per POSIX. + * Otherwise, it is an unknown option character (or ':'). */ - if (optchar == (int)'-') + if (optchar == (int)'-' && *place == '\0') return (-1); - /* option letter unknown or ':' */ if (!*place) ++optind; if (PRINT_ERROR) |