Re: add non-option reordering to in-tree getopt_long - Mailing list pgsql-hackers

From Kyotaro Horiguchi
Subject Re: add non-option reordering to in-tree getopt_long
Date
Msg-id 20230616.165138.1460643839992276252.horikyota.ntt@gmail.com
Whole thread Raw
In response to Re: add non-option reordering to in-tree getopt_long  (Nathan Bossart <nathandbossart@gmail.com>)
Responses Re: add non-option reordering to in-tree getopt_long
List pgsql-hackers
At Thu, 15 Jun 2023 21:58:28 -0700, Nathan Bossart <nathandbossart@gmail.com> wrote in 
> On Fri, Jun 16, 2023 at 10:30:09AM +0900, Michael Paquier wrote:
> > On Thu, Jun 15, 2023 at 05:09:59PM -0700, Nathan Bossart wrote:
> >> I've attached a new version of the patch that omits the
> >> POSIXLY_CORRECT stuff.
> > 
> > This looks OK at quick glance, though you may want to document at the
> > top of getopt_long() the reordering business with the non-options?
> 
> I added a comment to this effect in v3.  I also noticed that '-' wasn't
> properly handled as a non-option, so I've tried to fix that as well.

(Honestly, the rearrangement code looks somewhat tricky to grasp..)

It doesn't work properly if '--' is involved.

For example, consider the following options (even though they don't
work for the command).

psql -t -T hoho -a hoge -- -1 hage hige huge

After the function returns -1, the argv array looks like this. The
"[..]" indicates the position of optind.

psql -t -T hoho -a -- [-1] hage hige huge hoge

This is clearly incorrect since "hoge" gets moved to the end.  The
rearrangement logic needs to take into account the '--'.  For your
information, the glibc version yields the following result for the
same options.

psql -t -T hoho -a -- [hoge] -1 hage hige huge

regards.

-- 
Kyotaro Horiguchi
NTT Open Source Software Center



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Support to define custom wait events for extensions
Next
From: Masahiko Sawada
Date:
Subject: Re: Use the enum value CRS_EXPORT_SNAPSHOT instead of "0"