summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authormillert <>2002-12-08 07:23:09 +0000
committermillert <>2002-12-08 07:23:09 +0000
commit4dd944fe0af3fd52ded537cb0346f79b05ec9c04 (patch)
tree7241e0605573636722f1119d3bae94e291b7eb77 /src/lib
parentd364cd2a62331a9116bb48fdbf5c81abc715df85 (diff)
downloadopenbsd-4dd944fe0af3fd52ded537cb0346f79b05ec9c04.tar.gz
openbsd-4dd944fe0af3fd52ded537cb0346f79b05ec9c04.tar.bz2
openbsd-4dd944fe0af3fd52ded537cb0346f79b05ec9c04.zip
BSD getopt() supports '-' in the optstring so we should too.
This is used by a few programs such as man and su.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/stdlib/getopt_long.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/lib/libc/stdlib/getopt_long.c b/src/lib/libc/stdlib/getopt_long.c
index c4f09cb23e..2eec98530a 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.7 2002/12/07 19:48:32 millert Exp $ */ 1/* $OpenBSD: getopt_long.c,v 1.8 2002/12/08 07:23:09 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/*
@@ -64,7 +64,7 @@
64 */ 64 */
65 65
66#if defined(LIBC_SCCS) && !defined(lint) 66#if defined(LIBC_SCCS) && !defined(lint)
67static char *rcsid = "$OpenBSD: getopt_long.c,v 1.7 2002/12/07 19:48:32 millert Exp $"; 67static char *rcsid = "$OpenBSD: getopt_long.c,v 1.8 2002/12/08 07:23:09 millert Exp $";
68#endif /* LIBC_SCCS and not lint */ 68#endif /* LIBC_SCCS and not lint */
69 69
70#include <err.h> 70#include <err.h>
@@ -348,8 +348,7 @@ start:
348 nonopt_start = nonopt_end = -1; 348 nonopt_start = nonopt_end = -1;
349 return (-1); 349 return (-1);
350 } 350 }
351 if ((*(place = nargv[optind]) != '-') 351 if (*(place = nargv[optind]) != '-') { /* found non-option */
352 || (place[1] == '\0')) { /* found non-option */
353 place = EMSG; 352 place = EMSG;
354 if (flags & FLAG_ALLARGS) { 353 if (flags & FLAG_ALLARGS) {
355 /* 354 /*
@@ -383,8 +382,11 @@ start:
383 if (nonopt_start != -1 && nonopt_end == -1) 382 if (nonopt_start != -1 && nonopt_end == -1)
384 nonopt_end = optind; 383 nonopt_end = optind;
385 384
386 /* check for "--" or "--foo" with no long options */ 385 /*
387 if (*++place == '-' && 386 * Check for "--" or "--foo" with no long options
387 * but if place is simply "-" leave it unmolested.
388 */
389 if (place[1] != '\0' && *++place == '-' &&
388 (place[1] == '\0' || long_options == NULL)) { 390 (place[1] == '\0' || long_options == NULL)) {
389 optind++; 391 optind++;
390 place = EMSG; 392 place = EMSG;
@@ -402,8 +404,13 @@ start:
402 } 404 }
403 } 405 }
404 406
405 /* check long options if we have any */ 407 /*
406 if (long_options != NULL && 408 * Check long options if:
409 * 1) we were passed some
410 * 2) the arg is not just "-"
411 * 3) either the arg starts with -- we are getopt_long_only()
412 */
413 if (long_options != NULL && place != nargv[optind] &&
407 (*place == '-' || (flags & FLAG_LONGONLY))) { 414 (*place == '-' || (flags & FLAG_LONGONLY))) {
408 short_too = 0; 415 short_too = 0;
409 if (*place == '-') 416 if (*place == '-')