Module Name:    src
Committed By:   christos
Date:           Thu Jun  5 22:00:22 UTC 2014

Modified Files:
        src/lib/libc/stdlib: getopt.3 getopt.c

Log Message:
Bring getopt(3) inline with getopt_long(3): recognize option:: as an optional
option.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libc/stdlib/getopt.3
cvs rdiff -u -r1.28 -r1.29 src/lib/libc/stdlib/getopt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/stdlib/getopt.3
diff -u src/lib/libc/stdlib/getopt.3:1.32 src/lib/libc/stdlib/getopt.3:1.33
--- src/lib/libc/stdlib/getopt.3:1.32	Mon Mar 22 15:30:54 2010
+++ src/lib/libc/stdlib/getopt.3	Thu Jun  5 18:00:22 2014
@@ -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 @@ 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
+.Nx
+extension.
 For example, an option string
 .Qq x
 recognizes an option

Index: src/lib/libc/stdlib/getopt.c
diff -u src/lib/libc/stdlib/getopt.c:1.28 src/lib/libc/stdlib/getopt.c:1.29
--- src/lib/libc/stdlib/getopt.c:1.28	Fri Mar 20 09:56:57 2009
+++ src/lib/libc/stdlib/getopt.c	Thu Jun  5 18:00:22 2014
@@ -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 @@ getopt(int nargc, char * const nargv[], 
 		   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 {

Reply via email to