Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/stdlib Bring getopt(3) inline with getopt_long(3): ...
details: https://anonhg.NetBSD.org/src/rev/0b7ebb66eeca
branches: trunk
changeset: 329724:0b7ebb66eeca
user: christos <christos%NetBSD.org@localhost>
date: Thu Jun 05 22:00:22 2014 +0000
description:
Bring getopt(3) inline with getopt_long(3): recognize option:: as an optional
option.
diffstat:
lib/libc/stdlib/getopt.3 | 15 +++++++++++++--
lib/libc/stdlib/getopt.c | 10 ++++++++--
2 files changed, 21 insertions(+), 4 deletions(-)
diffs (67 lines):
diff -r 59228bc7a536 -r 0b7ebb66eeca lib/libc/stdlib/getopt.3
--- a/lib/libc/stdlib/getopt.3 Thu Jun 05 21:06:47 2014 +0000
+++ b/lib/libc/stdlib/getopt.3 Thu Jun 05 22:00:22 2014 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: getopt.3,v 1.32 2010/03/22 19:30:54 joerg Exp $
+.\" $NetBSD: getopt.3,v 1.33 2014/06/05 22:00:22 christos Exp $
.\"
.\" Copyright (c) 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)getopt.3 8.5 (Berkeley) 4/27/95
.\"
-.Dd September 10, 2003
+.Dd June 5, 2014
.Dt GETOPT 3
.Os
.Sh NAME
@@ -64,6 +64,17 @@
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
+.Nx
+extension.
For example, an option string
.Qq x
recognizes an option
diff -r 59228bc7a536 -r 0b7ebb66eeca lib/libc/stdlib/getopt.c
--- a/lib/libc/stdlib/getopt.c Thu Jun 05 21:06:47 2014 +0000
+++ b/lib/libc/stdlib/getopt.c Thu Jun 05 22:00:22 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getopt.c,v 1.28 2009/03/20 13:56:57 joerg Exp $ */
+/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: getopt.c,v 1.28 2009/03/20 13:56:57 joerg Exp $");
+__RCSID("$NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $");
#include "namespace.h"
@@ -116,6 +116,12 @@
entire next argument. */
if (*place)
optarg = __UNCONST(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 {
Home |
Main Index |
Thread Index |
Old Index