[Midnightbsd-cvs] src [10544] update getopt

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Thu Jun 7 19:06:13 EDT 2018


Revision: 10544
          http://svnweb.midnightbsd.org/src/?rev=10544
Author:   laffer1
Date:     2018-06-07 19:06:13 -0400 (Thu, 07 Jun 2018)
Log Message:
-----------
update getopt

Modified Paths:
--------------
    trunk/lib/libc/stdlib/getopt.3
    trunk/lib/libc/stdlib/getopt.c
    trunk/lib/libc/stdlib/getopt_long.3
    trunk/lib/libc/stdlib/getopt_long.c

Property Changed:
----------------
    trunk/lib/libc/stdlib/getopt.3
    trunk/lib/libc/stdlib/getopt_long.3

Modified: trunk/lib/libc/stdlib/getopt.3
===================================================================
--- trunk/lib/libc/stdlib/getopt.3	2018-06-07 23:04:26 UTC (rev 10543)
+++ trunk/lib/libc/stdlib/getopt.3	2018-06-07 23:06:13 UTC (rev 10544)
@@ -1,4 +1,5 @@
-.\"	$NetBSD: getopt.3,v 1.31 2003/09/23 10:26:54 wiz Exp $
+.\" $MidnightBSD$
+.\"	$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.
@@ -11,7 +12,7 @@
 .\" 2. Redistributions in binary form must reproduce the above copyright
 .\"    notice, this list of conditions and the following disclaimer in the
 .\"    documentation and/or other materials provided with the distribution.
-.\" 4. Neither the name of the University nor the names of its contributors
+.\" 3. Neither the name of the University nor the names of its contributors
 .\"    may be used to endorse or promote products derived from this software
 .\"    without specific prior written permission.
 .\"
@@ -28,9 +29,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)getopt.3	8.5 (Berkeley) 4/27/95
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdlib/getopt.3 268396 2014-07-08 13:16:03Z pluknet $
 .\"
-.Dd April 27, 1995
+.Dd June 5, 2014
 .Dt GETOPT 3
 .Os
 .Sh NAME
@@ -65,6 +66,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
+.Tn GNU
+extension.
 For example, an option string
 .Li \&"x"
 recognizes an option


Property changes on: trunk/lib/libc/stdlib/getopt.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdlib/getopt.c
===================================================================
--- trunk/lib/libc/stdlib/getopt.c	2018-06-07 23:04:26 UTC (rev 10543)
+++ trunk/lib/libc/stdlib/getopt.c	2018-06-07 23:06:13 UTC (rev 10544)
@@ -1,4 +1,5 @@
-/*	$NetBSD: getopt.c,v 1.26 2003/08/07 16:43:40 agc Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $	*/
 
 /*
  * Copyright (c) 1987, 1993, 1994
@@ -12,7 +13,7 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
@@ -33,7 +34,7 @@
 static char sccsid[] = "@(#)getopt.c	8.3 (Berkeley) 4/27/95";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdlib/getopt.c 268352 2014-07-07 02:47:41Z pfg $");
 
 #include "namespace.h"
 #include <stdio.h>
@@ -59,10 +60,7 @@
  *	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 +113,12 @@
 		   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 {

Modified: trunk/lib/libc/stdlib/getopt_long.3
===================================================================
--- trunk/lib/libc/stdlib/getopt_long.3	2018-06-07 23:04:26 UTC (rev 10543)
+++ trunk/lib/libc/stdlib/getopt_long.3	2018-06-07 23:06:13 UTC (rev 10544)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
 .\"	$OpenBSD: getopt_long.3,v 1.10 2004/01/06 23:44:28 fgsch Exp $
 .\"	$NetBSD: getopt_long.3,v 1.14 2003/08/07 16:43:40 agc Exp $
 .\"
@@ -29,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)getopt.3	8.5 (Berkeley) 4/27/95
-.\" $FreeBSD$
+.\" $FreeBSD: stable/10/lib/libc/stdlib/getopt_long.3 228885 2011-12-26 03:14:37Z gjb $
 .\"
 .Dd December 25, 2011
 .Dt GETOPT_LONG 3


Property changes on: trunk/lib/libc/stdlib/getopt_long.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdlib/getopt_long.c
===================================================================
--- trunk/lib/libc/stdlib/getopt_long.c	2018-06-07 23:04:26 UTC (rev 10543)
+++ trunk/lib/libc/stdlib/getopt_long.c	2018-06-07 23:06:13 UTC (rev 10544)
@@ -1,4 +1,5 @@
-/*	$OpenBSD: getopt_long.c,v 1.21 2006/09/22 17:22:05 millert Exp $	*/
+/* $MidnightBSD$ */
+/*	$OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $	*/
 /*	$NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $	*/
 
 /*
@@ -35,13 +36,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *        This product includes software developed by the NetBSD
- *        Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -62,7 +56,7 @@
 #endif /* LIBC_SCCS and not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/lib/libc/stdlib/getopt_long.c 268355 2014-07-07 05:31:50Z ache $");
 
 #include <err.h>
 #include <errno.h>
@@ -255,7 +249,7 @@
 		if (short_too && current_argv_len == 1)
 			continue;
 
-		if (match == -1)        /* first partial match */
+		if (match == -1)	/* first partial match */
 			match = i;
 		else if ((flags & FLAG_LONGONLY) ||
 			 long_options[i].has_arg !=
@@ -366,37 +360,31 @@
 {
 	char *oli;				/* option letter list index */
 	int optchar, short_too;
-	int posixly_correct;	/* no static, can be changed on the fly */
+	static int posixly_correct = -1;
 
 	if (options == NULL)
 		return (-1);
 
 	/*
+	 * XXX Some GNU programs (like cvs) set optind to 0 instead of
+	 * XXX using optreset.  Work around this braindamage.
+	 */
+	if (optind == 0)
+		optind = optreset = 1;
+
+	/*
 	 * Disable GNU extensions if POSIXLY_CORRECT is set or options
 	 * string begins with a '+'.
 	 */
-	posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
-#ifdef GNU_COMPATIBLE
+	if (posixly_correct == -1 || optreset)
+		posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
 	if (*options == '-')
 		flags |= FLAG_ALLARGS;
 	else if (posixly_correct || *options == '+')
 		flags &= ~FLAG_PERMUTE;
-#else
-	if (posixly_correct || *options == '+')
-		flags &= ~FLAG_PERMUTE;
-	else if (*options == '-')
-		flags |= FLAG_ALLARGS;
-#endif
 	if (*options == '+' || *options == '-')
 		options++;
 
-	/*
-	 * XXX Some GNU programs (like cvs) set optind to 0 instead of
-	 * XXX using optreset.  Work around this braindamage.
-	 */
-	if (optind == 0)
-		optind = optreset = 1;
-
 	optarg = NULL;
 	if (optreset)
 		nonopt_start = nonopt_end = -1;



More information about the Midnightbsd-cvs mailing list