diff options
author | millert <> | 2004-02-04 18:17:25 +0000 |
---|---|---|
committer | millert <> | 2004-02-04 18:17:25 +0000 |
commit | b5f1b51f776a16e2dfaf65d9bb74fbc361a8e032 (patch) | |
tree | c75c0df6fb8f6f2b1af4b7f9b2e5e39beaad134f | |
parent | f4471dfe8dbc436171f499295c8c86950583edf3 (diff) | |
download | openbsd-b5f1b51f776a16e2dfaf65d9bb74fbc361a8e032.tar.gz openbsd-b5f1b51f776a16e2dfaf65d9bb74fbc361a8e032.tar.bz2 openbsd-b5f1b51f776a16e2dfaf65d9bb74fbc361a8e032.zip |
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.
-rw-r--r-- | src/lib/libc/stdlib/getopt_long.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/lib/libc/stdlib/getopt_long.c b/src/lib/libc/stdlib/getopt_long.c index 1f7f5baa8b..6079ce3503 100644 --- a/src/lib/libc/stdlib/getopt_long.c +++ b/src/lib/libc/stdlib/getopt_long.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getopt_long.c,v 1.15 2003/09/22 23:45:22 millert Exp $ */ | 1 | /* $OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $ */ |
2 | /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ | 2 | /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -57,7 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #if defined(LIBC_SCCS) && !defined(lint) | 59 | #if defined(LIBC_SCCS) && !defined(lint) |
60 | static char *rcsid = "$OpenBSD: getopt_long.c,v 1.15 2003/09/22 23:45:22 millert Exp $"; | 60 | static char *rcsid = "$OpenBSD: getopt_long.c,v 1.16 2004/02/04 18:17:25 millert Exp $"; |
61 | #endif /* LIBC_SCCS and not lint */ | 61 | #endif /* LIBC_SCCS and not lint */ |
62 | 62 | ||
63 | #include <err.h> | 63 | #include <err.h> |
@@ -379,11 +379,9 @@ start: | |||
379 | nonopt_end = optind; | 379 | nonopt_end = optind; |
380 | 380 | ||
381 | /* | 381 | /* |
382 | * Check for "--" or "--foo" with no long options | 382 | * If we have "-" do nothing, if "--" we are done. |
383 | * but if place is simply "-" leave it unmolested. | ||
384 | */ | 383 | */ |
385 | if (place[1] != '\0' && *++place == '-' && | 384 | if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { |
386 | (place[1] == '\0' || long_options == NULL)) { | ||
387 | optind++; | 385 | optind++; |
388 | place = EMSG; | 386 | place = EMSG; |
389 | /* | 387 | /* |
@@ -423,14 +421,15 @@ start: | |||
423 | } | 421 | } |
424 | 422 | ||
425 | if ((optchar = (int)*place++) == (int)':' || | 423 | if ((optchar = (int)*place++) == (int)':' || |
424 | optchar == (int)'-' && *place != '\0' || | ||
426 | (oli = strchr(options, optchar)) == NULL) { | 425 | (oli = strchr(options, optchar)) == NULL) { |
427 | /* | 426 | /* |
428 | * If the user didn't specify '-' as an option, | 427 | * If the user specified "-" and '-' isn't listed in |
429 | * assume it means -1 as POSIX specifies. | 428 | * options, return -1 (non-option) as per POSIX. |
429 | * Otherwise, it is an unknown option character (or ':'). | ||
430 | */ | 430 | */ |
431 | if (optchar == (int)'-') | 431 | if (optchar == (int)'-' && *place == '\0') |
432 | return (-1); | 432 | return (-1); |
433 | /* option letter unknown or ':' */ | ||
434 | if (!*place) | 433 | if (!*place) |
435 | ++optind; | 434 | ++optind; |
436 | if (PRINT_ERROR) | 435 | if (PRINT_ERROR) |