Re: [hackers] [sbase][PATCH] Support -- in all utilities except echo(1)

From: Michael Forney <mforney_AT_mforney.org>
Date: Fri, 28 Jun 2019 00:52:33 -0700

Hi Mattias,

I'm really sorry for ignoring this for so long. Someone asked me about
the `argv0 = *argv, argv0 ? (argc--, argv++) : (void *)0;` one-liner,
and I remembered this patch. I finally took the time to investigate
this issue in more detail.

On 2018-07-08, Mattias Andrée <maandree_AT_kth.se> wrote:
> In POSIX-2017 it was clarified via the documentation for
> basename(1) and dirname(1) that all programs should support
> -- unless specified otherwise.

I was confused by this for a bit, but I think you are referring to
http://austingroupbugs.net/view.php?id=192, which was not present in
the 2008 edition[0], but did make it into the 2013 edition[1].

As far as I know, unless the documentation states that a utility shall
conform to the Utility Syntax Guidelines, it is not required to
support `--`. However, it does use the language "should" which
means[2]:

        For an implementation that conforms to POSIX.1-2017, describes a
feature or behavior that is recommended but not mandatory.

It looks like these tools formerly supported `--`, but this was
removed in 9016d288[3], with the justification that echo(1) is
mandated to *not* support `--` and that there is no reason why other
tools with no options should handle it. I would argue that there *is*
a reason to support `--`, and that is the Utility Syntax Guidelines.
echo(1) is an exception that is explicitly called out, but a single
exception shouldn't set a precedent for other tools. In fact, tty(1)
is actually required to support the Utility Syntax Guidelines[4], so
9016d288 actually breaks POSIX conformance. The examples you mentioned
in basename(1) and dirname(1), and also a note about `--` I found in
expr(1) seem to support this view.

Rather than add a special ENOFLAGS macro, I am tempted to revert
9016d288 instead. The question that remains is how to handle arguments
that look like options (start with `-`) for tools that don't have any
specified options. It seems for some tools it is important to treat
them as operands (e.g. printf, expr), but for others that are commonly
extended with additional options, it might make sense to fail with
usage() to catch unsupported uses (e.g. hostname, tsort, chroot).

[0] http://pubs.opengroup.org/onlinepubs/9699919799.2008edition/utilities/basename.html
[1] http://pubs.opengroup.org/onlinepubs/9699919799.2013edition/utilities/basename.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/basedefs/V1_chap01.html#tag_01_05_06
[3] https://git.suckless.org/sbase/commit/9016d288f1cd03bf514fe84d537b203040e1ccf8.html
[4] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tty.html#tag_20_135_04
Received on Fri Jun 28 2019 - 09:52:33 CEST

This archive was generated by hypermail 2.3.0 : Fri Jun 28 2019 - 10:24:24 CEST