On Tue, Mar 17, 2020 at 02:14:58PM +0100, Martijn van Duren wrote:
> Included millert, since he imported this code.
> He might shed some more light on what's intended.
> 
> On 3/15/20 11:27 PM, 0xef967...@gmail.com wrote:
> > On Sun, Mar 15, 2020 at 07:32:52PM +0100, Martijn van Duren wrote:
> >> tl;dr new diff below
> > 
> > Check with:
> > 
> > OPTS=r- ./getopt-test-MvD2 -r-
> > getopt-test-MvD2: unknown option -- -
> >  <r> #U- |
> > 
> > With the unpatched code, my patch, and the original 44BSD, it's:
> > 
> > OPTS=r- ./getopt-test-O -r-
> > {./getopt-test-O} <r> <-> |
> > 
> > See proposed fix at the end.
> 
> This is intentional. From getopt_long(3):
>
>          OpenBSD  a ‘-’ within the option string matches a ‘-’ (single
>                   dash) on the command line.  This functionality is
>                   provided for backward compatibility with programs,
>                   such as su(1), that use ‘-’ as an option flag.  This
>                   practice is wrong, and should not be used in any
>                   current development.

I don't get your point, sorry. My patch didn't mean to change that.
Nor do I think that it should be changed (if that matters).

My stupid and unnecessary "(optchar == (int)'-' && oli == options)"
check was breaking the case where someone meant to use both the
GNU-like optstring-starting-with-dash and the BSD dashes-in-optstring
features, by using an optstring like "--xy" or "-x-y".

As I mentioned, that was a mistake.

For the reference, here is an updated patch, without that check:

--- getopt-long.c~      2020-03-12 02:23:29.028903616 +0200
+++ getopt-long.c       2020-03-15 23:46:07.988119523 +0200
@@ -418,15 +418,7 @@
        }
 
        if ((optchar = (int)*place++) == (int)':' ||
-           (optchar == (int)'-' && *place != '\0') ||
            (oli = strchr(options, optchar)) == NULL) {
-               /*
-                * If the user specified "-" and  '-' isn't listed in
-                * options, return -1 (non-option) as per POSIX.
-                * Otherwise, it is an unknown option character (or ':').
-                */
-               if (optchar == (int)'-' && *place == '\0')
-                       return (-1);
                if (!*place)
                        ++optind;
                if (PRINT_ERROR)

Reply via email to