summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrad <>2004-02-13 07:14:52 +0000
committerbrad <>2004-02-13 07:14:52 +0000
commitec3df9335c2be86d2de19f2111bf4a15736c11bc (patch)
tree6425cbada60a5fdd1132da150868f8099764afd5
parent78ab25ab025c9fed3071a88e023672809401a6df (diff)
downloadopenbsd-ec3df9335c2be86d2de19f2111bf4a15736c11bc.tar.gz
openbsd-ec3df9335c2be86d2de19f2111bf4a15736c11bc.tar.bz2
openbsd-ec3df9335c2be86d2de19f2111bf4a15736c11bc.zip
MFC:
Fix by millert@ 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. ok deraadt@ millert@
-rw-r--r--src/lib/libc/stdlib/getopt_long.c19
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 124893051c..cc1d67b7e4 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.14 2003/06/17 21:56:24 millert Exp $ */ 1/* $OpenBSD: getopt_long.c,v 1.14.2.1 2004/02/13 07:14:52 brad 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)
60static char *rcsid = "$OpenBSD: getopt_long.c,v 1.14 2003/06/17 21:56:24 millert Exp $"; 60static char *rcsid = "$OpenBSD: getopt_long.c,v 1.14.2.1 2004/02/13 07:14:52 brad 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)