From: Karel Zak Date: Mon, 25 May 2026 11:33:34 +0000 (+0200) Subject: pipesz: merge help/version getopt loop into main loop X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47645c455e785857e9d8eb131ea11de6a1df61c3;p=thirdparty%2Futil-linux.git pipesz: merge help/version getopt loop into main loop The main() function scanned command-line options in two passes: the first pass checked for --help/--version, and the second processed normal options. When getopt_long encountered an unknown option in the first pass, it printed an error message. The same error was then printed again during the second pass, resulting in a duplicate "unrecognized option" message. Fix this by merging the first getopt_long loop into the main one, following the standard util-linux convention. Fixes: https://github.com/util-linux/util-linux/issues/3817 Signed-off-by: Karel Zak --- diff --git a/misc-utils/pipesz.c b/misc-utils/pipesz.c index a84eb807d..243b702e2 100644 --- a/misc-utils/pipesz.c +++ b/misc-utils/pipesz.c @@ -227,18 +227,6 @@ int main(int argc, char **argv) textdomain(PACKAGE); close_stdout_atexit(); - /* check for --help or --version */ - while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { - switch (c) { - case 'h': - usage(); - case 'V': - print_version(EXIT_SUCCESS); - } - } - - /* gather normal options */ - optind = 1; while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -276,6 +264,11 @@ int main(int argc, char **argv) case 'v': opt_verbose = TRUE; break; + + case 'V': + print_version(EXIT_SUCCESS); + case 'h': + usage(); default: errtryhelp(EXIT_FAILURE); }