mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibC: Make getopt
modify argv
again
A POSIX-compatibility fix was introduced in 64740a0214
to make the
compilation of the `diffutils` port work, which expected a
`char* const* argv` signature.
And indeed, the POSIX spec does not mention permutation of `argv`:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html
However, most implementations do modify `argv` as evidenced by
documentation such as:
https://refspecs.linuxbase.org/LSB_5.0.0/LSB-Core-generic
/LSB-Core-generic/libutil-getopt-3.html
"The function prototype was aligned with POSIX 1003.1-2008 (ISO/IEC
9945-2009) despite the fact that it modifies argv, and the library
maintainers are unwilling to change this."
Change the behavior back to permutate `argc` to allow for the following
command line argument order to work again:
unzip ./file.zip -o target-dir
Without this change, `./file.zip` in the example above would have been
ignored completely.
This commit is contained in:
parent
d72aeb2e1a
commit
10e8b99038
2 changed files with 13 additions and 14 deletions
|
@ -333,7 +333,7 @@ TEST_CASE(stop_on_first_non_option)
|
|||
EXPECT_EQ(positionals[0], "one");
|
||||
|
||||
// Do not stop on first non-option; arguments in wrong order
|
||||
// Expected: parser chokes on the positional argument
|
||||
// Expected: bool options are set and one positional argument is filled
|
||||
bool_opt1 = false;
|
||||
bool_opt2 = false;
|
||||
positionals = {};
|
||||
|
@ -343,7 +343,12 @@ TEST_CASE(stop_on_first_non_option)
|
|||
parser.add_option(bool_opt2, "bool_opt2", nullptr, 'c');
|
||||
parser.add_positional_argument(positionals, "pos", "pos", Core::ArgsParser::Required::Yes);
|
||||
});
|
||||
EXPECT_EQ(parser_result, false);
|
||||
EXPECT_EQ(parser_result, true);
|
||||
EXPECT_EQ(bool_opt1, true);
|
||||
EXPECT_EQ(bool_opt2, true);
|
||||
EXPECT_EQ(positionals.size(), 1u);
|
||||
if (positionals.size() == 1u)
|
||||
EXPECT_EQ(positionals[0], "one");
|
||||
|
||||
// Stop on first non-option; arguments in correct order
|
||||
// Expected: bool options are set and one positional argument is filled
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue