From owner-svn-src-all@FreeBSD.ORG Mon Jul 7 02:47:42 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 5B912267; Mon, 7 Jul 2014 02:47:42 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 476532E67; Mon, 7 Jul 2014 02:47:42 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s672lg0U079845; Mon, 7 Jul 2014 02:47:42 GMT (envelope-from pfg@svn.freebsd.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s672lfMx079842; Mon, 7 Jul 2014 02:47:41 GMT (envelope-from pfg@svn.freebsd.org) Message-Id: <201407070247.s672lfMx079842@svn.freebsd.org> From: "Pedro F. Giffuni" Date: Mon, 7 Jul 2014 02:47:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r268352 - stable/10/lib/libc/stdlib X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jul 2014 02:47:42 -0000 Author: pfg Date: Mon Jul 7 02:47:41 2014 New Revision: 268352 URL: http://svnweb.freebsd.org/changeset/base/268352 Log: 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 Modified: stable/10/lib/libc/stdlib/getopt.3 stable/10/lib/libc/stdlib/getopt.c stable/10/lib/libc/stdlib/getopt_long.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/stdlib/getopt.3 ============================================================================== --- stable/10/lib/libc/stdlib/getopt.3 Mon Jul 7 00:27:09 2014 (r268351) +++ stable/10/lib/libc/stdlib/getopt.3 Mon Jul 7 02:47:41 2014 (r268352) @@ -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 Modified: stable/10/lib/libc/stdlib/getopt.c ============================================================================== --- stable/10/lib/libc/stdlib/getopt.c Mon Jul 7 00:27:09 2014 (r268351) +++ stable/10/lib/libc/stdlib/getopt.c Mon Jul 7 02:47:41 2014 (r268352) @@ -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 wi * 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 { Modified: stable/10/lib/libc/stdlib/getopt_long.c ============================================================================== --- stable/10/lib/libc/stdlib/getopt_long.c Mon Jul 7 00:27:09 2014 (r268351) +++ stable/10/lib/libc/stdlib/getopt_long.c Mon Jul 7 02:47:41 2014 (r268352) @@ -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 $ */ /*