From patchwork Thu Aug 4 15:59:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jilles Tjoelker X-Patchwork-Id: 9263877 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EE46D6048F for ; Thu, 4 Aug 2016 16:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DFCAD2840D for ; Thu, 4 Aug 2016 16:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D48D928410; Thu, 4 Aug 2016 16:00:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 041BD2840D for ; Thu, 4 Aug 2016 16:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758792AbcHDQAc (ORCPT ); Thu, 4 Aug 2016 12:00:32 -0400 Received: from relay02.stack.nl ([131.155.140.104]:63487 "EHLO mx1.stack.nl" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758737AbcHDQAa (ORCPT ); Thu, 4 Aug 2016 12:00:30 -0400 Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id B8A673592E6; Thu, 4 Aug 2016 17:59:08 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 89CAD28494; Thu, 4 Aug 2016 17:59:08 +0200 (CEST) Date: Thu, 4 Aug 2016 17:59:08 +0200 From: Jilles Tjoelker To: Kylie McClain Cc: dash@vger.kernel.org, Kylie McClain Subject: Re: [PATCH 2/2] histedit: Remove non-glibc fallback code Message-ID: <20160804155908.GA94936@stack.nl> References: <20160804055411.23558-1-somasissounds@gmail.com> <20160804055411.23558-2-somasissounds@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160804055411.23558-2-somasissounds@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, Aug 04, 2016 at 01:54:11AM -0400, Kylie McClain wrote: > From: Kylie McClain > This fallback code seems to go back the import of the repository back > in 2005, it fails on musl libc, and there aren't any comments > explaining why this difference is needed. Regardless, any > compatibility ifdefs should probably be checking macros defined on > systems that need a different code path, rather than just having > fallback code for non-glibc. Setting optreset is required on FreeBSD and NetBSD which do not recognize setting optind to 0. POSIX specifies neither of these methods to reset getopt(). However, removing the dependency on this feature is simple. The shell already features a function nextopt() that can be used to parse options and is automatically set up for builtins. From 23da600dcff616662a93f307420d9142598e2cae Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Thu, 4 Aug 2016 17:51:12 +0200 Subject: [PATCH 1/2] [HISTEDIT] Stop depending on getopt reset feature. Instead, use our own nextopt() function. --- src/histedit.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/histedit.c b/src/histedit.c index 94465d7..ec45065 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -214,13 +214,8 @@ histcmd(int argc, char **argv) if (argc == 1) sh_error("missing history argument"); -#ifdef __GLIBC__ - optind = 0; -#else - optreset = 1; optind = 1; /* initialize getopt */ -#endif while (not_fcnumber(argv[optind]) && - (ch = getopt(argc, argv, ":e:lnrs")) != -1) + (ch = nextopt(":e:lnrs")) != '\0') switch ((char)ch) { case 'e': editor = optionarg;