"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: getopt: BSD or GNU?
To:
Christian Weisgerber <naddy@mips.inka.de>
Cc:
gameoftrees@openbsd.org
Date:
Sun, 27 Sep 2020 11:40:38 +0200

Download raw body.

Thread
  • Christian Weisgerber:

    getopt: BSD or GNU?

    • Stefan Sperling:

      getopt: BSD or GNU?

On Sat, Sep 26, 2020 at 11:36:56PM +0200, Christian Weisgerber wrote:
> Sadly, there is no portable way to reset getopt(3).  POSIX is silent
> on the issue.
> 
> The BSD way is:
>         optind = 1;
>         optreset = 1;
> 
> The GNU way is:
>         optind = 0;
> 
> These are mutually exclusive on the application side.  OpenBSD's
> getopt supports both and tog.c uses a nonsensical mix.
> 
> We should make up our mind and go with one or the other.  I don't
> really care which one to choose, some platforms will require a patch
> either way, but the BSD scheme has the minor advantage that optreset
> will trigger a compile error if unavailable, while lack of support
> for optind=0 will only manifest at run time.

I think we should prefer the BSD way.

> The fact that we mix getopt_long() and getopt() does not affect
> this, although switching everything to non-POSIX getopt_long() and
> optind=0 would also take care of it.  (Alternatively, do we need
> getopt_long at all?)

getopt_long is only used to support 'got/tog --version'. This was in
response to a question from a user who pointed out that all of git,
svn and hg support this option while got was printing a usage message.
The corresponding single-letter option is -V which isn't 100% intuitive.