From owner-svn-src-head@FreeBSD.ORG Tue Dec 14 01:16:56 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 840C2106564A; Tue, 14 Dec 2010 01:16:56 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 72B348FC1A; Tue, 14 Dec 2010 01:16:56 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBE1GuPZ099145; Tue, 14 Dec 2010 01:16:56 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBE1GuSk099143; Tue, 14 Dec 2010 01:16:56 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201012140116.oBE1GuSk099143@svn.freebsd.org> From: Xin LI Date: Tue, 14 Dec 2010 01:16:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216423 - head/usr.bin/printf X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Dec 2010 01:16:56 -0000 Author: delphij Date: Tue Dec 14 01:16:56 2010 New Revision: 216423 URL: http://svn.freebsd.org/changeset/base/216423 Log: IEEE Std 1003.1-2008, Section 1.4, Utility Description Defaults says that when the options section is listed as "None", utility shall recognize "--" as a first argument to be discarded. This implementation is largely based on OpenBSD implementation but we do slightly differently: a) We skip argv[0] as the first step; b) We test whether the next argument is "--" and ignore it. With this change one will get: %printf usage: printf format [arguments ...] %printf -v -v%printf -- -v -v% %printf -- usage: printf format [arguments ...] Which matches the behavior observed on a Debian system but different from the Illumos change. Modified: head/usr.bin/printf/printf.c Modified: head/usr.bin/printf/printf.c ============================================================================== --- head/usr.bin/printf/printf.c Tue Dec 14 00:21:34 2010 (r216422) +++ head/usr.bin/printf/printf.c Tue Dec 14 01:16:56 2010 (r216423) @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) { size_t len; - int ch, chopped, end, rval; + int chopped, end, rval; char *format, *fmt, *start; #ifndef SHELL @@ -111,15 +111,15 @@ main(int argc, char *argv[]) #ifdef SHELL optreset = 1; optind = 1; opterr = 0; /* initialize getopt */ #endif - while ((ch = getopt(argc, argv, "")) != -1) - switch (ch) { - case '?': - default: - usage(); - /* NOTREACHED */ - } - argc -= optind; - argv += optind; + /* Skip argv[0] which is the process name */ + argv++; + argc--; + + /* Need to accept/ignore "--" option. */ + if (argc >= 1 && strcmp(*argv, "--") == 0) { + argc--; + argv++; + } if (argc < 1) { usage();