dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jilles Tjoelker <jilles@stack.nl>
To: Kylie McClain <somasissounds@gmail.com>
Cc: dash@vger.kernel.org, Kylie McClain <somasis@exherbo.org>
Subject: Re: [PATCH 2/2] histedit: Remove non-glibc fallback code
Date: Thu, 4 Aug 2016 17:59:08 +0200	[thread overview]
Message-ID: <20160804155908.GA94936@stack.nl> (raw)
In-Reply-To: <20160804055411.23558-2-somasissounds@gmail.com>

On Thu, Aug 04, 2016 at 01:54:11AM -0400, Kylie McClain wrote:
> From: Kylie McClain <somasis@exherbo.org>

> 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 <jilles@stack.nl>
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;
-- 
2.9.2

-- 
Jilles Tjoelker

  reply	other threads:[~2016-08-04 16:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04  5:54 [PATCH 1/2] mkbuiltins: Use a `while` loop rather than `nl` Kylie McClain
2016-08-04  5:54 ` [PATCH 2/2] histedit: Remove non-glibc fallback code Kylie McClain
2016-08-04 15:59   ` Jilles Tjoelker [this message]
2016-08-08 15:50     ` Jilles Tjoelker
2016-08-04 17:17 ` [PATCH 1/2] mkbuiltins: Use a `while` loop rather than `nl` Harald van Dijk
2016-08-06  9:02   ` Seb
2016-08-07 10:17     ` Seb
2016-08-06 16:51   ` Harald van Dijk
2016-08-08 15:33   ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160804155908.GA94936@stack.nl \
    --to=jilles@stack.nl \
    --cc=dash@vger.kernel.org \
    --cc=somasis@exherbo.org \
    --cc=somasissounds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).