diff options
author | Ron Yorston <rmy@pobox.com> | 2022-11-24 14:44:52 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2022-11-24 15:01:05 +0000 |
commit | ed2c6fc1eeab6234f26f9e1817bba8a7d9c84063 (patch) | |
tree | 8e39ab8e01a882767fbc9dc0a46cd6007d2cece7 | |
parent | 1363e586c5eaf87df062db27f2419cb1b25e291f (diff) | |
download | busybox-w32-ed2c6fc1eeab6234f26f9e1817bba8a7d9c84063.tar.gz busybox-w32-ed2c6fc1eeab6234f26f9e1817bba8a7d9c84063.tar.bz2 busybox-w32-ed2c6fc1eeab6234f26f9e1817bba8a7d9c84063.zip |
getopt: use name supplied with '-n' to report error
On Windows:
$ getopt -o a -n my_script -- -z
getopt: unknown option -- z
On Linux:
$ getopt -o a -n my_script -- -z
my_script: unknown option -- z
The difference arises because the Mingw-w64 implementation of
getopt(3) uses __argv[0] to report errors, not the first element
of the argument array passed to it.
Make __argv[0] point to the name supplied with the '-n' option to
match behaviour when glibc getopt(3) is used.
(GitHub issue #274)
-rw-r--r-- | util-linux/getopt.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/util-linux/getopt.c b/util-linux/getopt.c index 4148586d3..42e0a2730 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c | |||
@@ -412,6 +412,11 @@ int getopt_main(int argc, char **argv) | |||
412 | bb_simple_error_msg_and_die("missing optstring argument"); | 412 | bb_simple_error_msg_and_die("missing optstring argument"); |
413 | } | 413 | } |
414 | 414 | ||
415 | #if ENABLE_PLATFORM_MINGW32 | ||
416 | // Mingw-w64 getopt(3) uses __argv[0] in error messages, not the | ||
417 | // first element of its argument array. | ||
418 | __argv[0] = | ||
419 | #endif | ||
415 | argv[n] = name ? name : argv[0]; | 420 | argv[n] = name ? name : argv[0]; |
416 | return generate_output(argv + n, argc - n, optstr, long_options); | 421 | return generate_output(argv + n, argc - n, optstr, long_options); |
417 | } | 422 | } |