From owner-svn-src-all@FreeBSD.ORG Sat May 10 19:18:50 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 581B977B; Sat, 10 May 2014 19:18:50 +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 39107F9D; Sat, 10 May 2014 19:18:50 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4AJIoKs088669; Sat, 10 May 2014 19:18:50 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4AJInll088664; Sat, 10 May 2014 19:18:49 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201405101918.s4AJInll088664@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 10 May 2014 19:18:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r265849 - in head/bin/sh: . tests/builtins X-SVN-Group: head 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: Sat, 10 May 2014 19:18:50 -0000 Author: jilles Date: Sat May 10 19:18:49 2014 New Revision: 265849 URL: http://svnweb.freebsd.org/changeset/base/265849 Log: sh: In getopts, unset OPTARG where POSIX says we should. Added: head/bin/sh/tests/builtins/getopts8.0 (contents, props changed) head/bin/sh/tests/builtins/getopts8.0.stdout (contents, props changed) Modified: head/bin/sh/options.c head/bin/sh/tests/builtins/Makefile Modified: head/bin/sh/options.c ============================================================================== --- head/bin/sh/options.c Sat May 10 19:10:31 2014 (r265848) +++ head/bin/sh/options.c Sat May 10 19:18:49 2014 (r265849) @@ -446,6 +446,7 @@ getopts(char *optstr, char *optvar, char int ind = 0; int err = 0; char s[10]; + const char *optarg = NULL; if ((p = *optptr) == NULL || *p == '\0') { /* Current word is done, advance */ @@ -471,14 +472,10 @@ atend: if (optstr[0] == ':') { s[0] = c; s[1] = '\0'; - err |= setvarsafe("OPTARG", s, 0); + optarg = s; } - else { + else out2fmt_flush("Illegal option -%c\n", c); - INTOFF; - (void) unsetvar("OPTARG"); - INTON; - } c = '?'; goto out; } @@ -491,14 +488,11 @@ atend: if (optstr[0] == ':') { s[0] = c; s[1] = '\0'; - err |= setvarsafe("OPTARG", s, 0); + optarg = s; c = ':'; } else { out2fmt_flush("No arg for -%c option\n", c); - INTOFF; - (void) unsetvar("OPTARG"); - INTON; c = '?'; } goto out; @@ -506,16 +500,21 @@ atend: if (p == **optnext) (*optnext)++; - setvarsafe("OPTARG", p, 0); + optarg = p; p = NULL; } - else - setvarsafe("OPTARG", "", 0); out: if (*optnext != NULL) ind = *optnext - optfirst + 1; *optptr = p; + if (optarg != NULL) + err |= setvarsafe("OPTARG", optarg, 0); + else { + INTOFF; + err |= unsetvar("OPTARG"); + INTON; + } fmtstr(s, sizeof(s), "%d", ind); err |= setvarsafe("OPTIND", s, VNOFUNC); s[0] = c; Modified: head/bin/sh/tests/builtins/Makefile ============================================================================== --- head/bin/sh/tests/builtins/Makefile Sat May 10 19:10:31 2014 (r265848) +++ head/bin/sh/tests/builtins/Makefile Sat May 10 19:18:49 2014 (r265849) @@ -85,6 +85,7 @@ FILES+= getopts4.0 FILES+= getopts5.0 FILES+= getopts6.0 FILES+= getopts7.0 +FILES+= getopts8.0 getopts8.0.stdout FILES+= hash1.0 hash1.0.stdout FILES+= hash2.0 hash2.0.stdout FILES+= hash3.0 hash3.0.stdout Added: head/bin/sh/tests/builtins/getopts8.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/builtins/getopts8.0 Sat May 10 19:18:49 2014 (r265849) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +set -- -yz -wx +opt=wrong1 OPTARG=wrong2 +while getopts :x opt; do + echo "$opt:${OPTARG-unset}" +done +echo "OPTIND=$OPTIND" Added: head/bin/sh/tests/builtins/getopts8.0.stdout ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/builtins/getopts8.0.stdout Sat May 10 19:18:49 2014 (r265849) @@ -0,0 +1,5 @@ +?:y +?:z +?:w +x:unset +OPTIND=3