summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2014-07-07 02:47:41 +0000
committerpfg <pfg@FreeBSD.org>2014-07-07 02:47:41 +0000
commit19e2403cf638d4a6e6e50c1d6117dec3c7189291 (patch)
tree691aea9cf5ce894315583f830b81832a0556cc57 /lib
parentd74df80505e5aecd77377aaec7c1a99a08716af7 (diff)
downloadFreeBSD-src-19e2403cf638d4a6e6e50c1d6117dec3c7189291.zip
FreeBSD-src-19e2403cf638d4a6e6e50c1d6117dec3c7189291.tar.gz
MFC r267745, r268268:
getopt(3): recognize option:: as GNU extension for "optional options". Also ANSIfy a function declaration. While here update the OpenBSD patch level in getopt_long.c as we already have the corresponding change. Obtained from: NetBSD MFC after: 2 weeks
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdlib/getopt.315
-rw-r--r--lib/libc/stdlib/getopt.c13
-rw-r--r--lib/libc/stdlib/getopt_long.c2
3 files changed, 22 insertions, 8 deletions
diff --git a/lib/libc/stdlib/getopt.3 b/lib/libc/stdlib/getopt.3
index 03a63ab..9ffe567 100644
--- a/lib/libc/stdlib/getopt.3
+++ b/lib/libc/stdlib/getopt.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: getopt.3,v 1.31 2003/09/23 10:26:54 wiz Exp $
+.\" $NetBSD: getopt.3,v 1.34 2014/06/05 22:09:50 wiz Exp $
.\"
.\" Copyright (c) 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -30,7 +30,7 @@
.\" @(#)getopt.3 8.5 (Berkeley) 4/27/95
.\" $FreeBSD$
.\"
-.Dd April 27, 1995
+.Dd June 5, 2014
.Dt GETOPT 3
.Os
.Sh NAME
@@ -65,6 +65,17 @@ The option string
may contain the following elements: individual characters, and
characters followed by a colon to indicate an option argument
is to follow.
+If an individual character is followed by two colons, then the
+option argument is optional;
+.Va optarg
+is set to the rest of the current
+.Va argv
+word, or
+.Dv NULL
+if there were no more characters in the current word.
+This is a
+.It Tn GNU
+extension.
For example, an option string
.Li \&"x"
recognizes an option
diff --git a/lib/libc/stdlib/getopt.c b/lib/libc/stdlib/getopt.c
index b9d2ae3..3929b32 100644
--- a/lib/libc/stdlib/getopt.c
+++ b/lib/libc/stdlib/getopt.c
@@ -1,4 +1,4 @@
-/* $NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $ */
+/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -59,10 +59,7 @@ char *optarg; /* argument associated with option */
* Parse argc/argv argument vector.
*/
int
-getopt(nargc, nargv, ostr)
- int nargc;
- char * const nargv[];
- const char *ostr;
+getopt(int nargc, char * const nargv[], const char *ostr)
{
static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
@@ -115,6 +112,12 @@ getopt(nargc, nargv, ostr)
entire next argument. */
if (*place)
optarg = place;
+ else if (oli[2] == ':')
+ /*
+ * GNU Extension, for optional arguments if the rest of
+ * the argument is empty, we return NULL
+ */
+ optarg = NULL;
else if (nargc > ++optind)
optarg = nargv[optind];
else {
diff --git a/lib/libc/stdlib/getopt_long.c b/lib/libc/stdlib/getopt_long.c
index 9f7f6d5..3b7f693 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.22 2006/10/04 21:29:04 jmc Exp $ */
+/* $OpenBSD: getopt_long.c,v 1.23 2007/10/31 12:34:57 chl Exp $ */
/* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */
/*
OpenPOWER on IntegriCloud