From patchwork Wed Jan 4 11:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13088500 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3825C4332F for ; Wed, 4 Jan 2023 11:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234001AbjADLdv (ORCPT ); Wed, 4 Jan 2023 06:33:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234268AbjADLdu (ORCPT ); Wed, 4 Jan 2023 06:33:50 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 720CFF0D for ; Wed, 4 Jan 2023 03:33:49 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 7790C650; Wed, 4 Jan 2023 12:33:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1672832026; bh=+9ZYAQnw0dnvfNmHkoJ6pachmekwMilPvZFeSybxkLQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=M1o26AOW1V48+i8/jgVvwJ1Y8Nxy1DVjyDbRZxiayh5gNh1u5Z8JLJ9N+ILJRLrY2 BhdQLNhJRsdclpKeqtmmZjZmB1AnnBZS6hVMK7Ian/9sYGOhz5vOqRFSmNg2MXRCRN n54wzQrQAMJSuBM9hUQK0jP1/TtHpJfhekoQIK0hYLsbuox8lsHw5zjLiyA8wy5JiE 5DZq8uAKZyhRrZtpmDezy0h8Xk8QkCD4tmiFZ2zFjkAjv++CBx2WtpEbCDPwkVzIrQ Ow2lTnHlcaLjqadAEPk0ZHfpjkIgeQa6yVBlxgEC/wN5rkJB90w3V/Wih7lPV0C2qb M9XcG4li1Gvnw== Date: Wed, 4 Jan 2023 12:33:45 +0100 From: =?utf-8?b?0L3QsNCx?= To: Herbert Xu Cc: dash@vger.kernel.org Subject: [PATCH v2 1/2] options: getopts: ignore first --, per POSIX Message-ID: <728796762ed62a1e9a38cf62762e57509e5027a2.1672831998.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20220429 Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org Issue 7, XCU, getopts, OPTIONS reads "None.", and getopts isn't a special built-in listed in sexion 2.14 ‒ this means that XCU, 1. Introduction, 1.4 Utility Description Defaults, OPTIONS, Default Behavior applies: Default Behavior: When this section is listed as "None.", it means that the implementation need not support any options. Standard utilities that do not accept options, but that do accept operands, shall recognize "--" as a first argument to be discarded. Test with: getopts -- d: a Correct output is no output, exit 1 Wrong output errors out with d: being an invalid argument name --- src/options.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/options.c b/src/options.c index a46c23b..337a8ee 100644 --- a/src/options.c +++ b/src/options.c @@ -409,6 +409,9 @@ getoptscmd(int argc, char **argv) { char **optbase; + nextopt(nullstr); + argc -= argptr - argv - 1; + argv = argptr - 1; if (argc < 3) sh_error("Usage: getopts optstring var [arg]"); else if (argc == 3) {