]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
treewide: fix newlines when using fputs
authorThomas Weißschuh <thomas@t-8ch.de>
Tue, 23 Jan 2024 19:22:21 +0000 (20:22 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Tue, 23 Jan 2024 19:35:03 +0000 (20:35 +0100)
The `fputs()` introduced in #2561 does not automatically include a
trailing newline which the original `puts()` did.
This broke the `--help` output of various utilities.

Changing all format strings to include a newline is not feasible as it
would force all translations to be adapted.

Instead introduce a new helper `fputsln()` that works as expected.

Documentation/boilerplate.c
disk-utils/blockdev.c
disk-utils/mkfs.cramfs.c
include/c.h
misc-utils/pipesz.c
misc-utils/uuidparse.c
misc-utils/wipefs.c
sys-utils/hwclock.c
sys-utils/lsirq.c

index 95915b5ccf7c7b0507e0b87c22670531c96f1478..4fc4383dacf2e4a83633f8ee6a92867345e547ed 100644 (file)
@@ -33,20 +33,20 @@ static void __attribute__((__noreturn__)) usage(void)
        fprintf(stdout, _(" %s [options] file...\n"), program_invocation_short_name);
 
        fputs(USAGE_SEPARATOR, stdout);
-       fputs(_("Short program description."), stdout);
+       fputsln(_("Short program description."), stdout);
 
        fputs(USAGE_OPTIONS, stdout);
-       fputs(_(" -n, --no-argument       option does not use argument"), stdout);
-       fputs(_("     --optional[=<arg>]  option argument is optional"), stdout);
-       fputs(_(" -r, --required <arg>    option requires an argument"), stdout);
-       fputs(_(" -z                      no long option"), stdout);
-       fputs(_("     --xyzzy             a long option only"), stdout);
-       fputs(_(" -e, --extremely-long-long-option\n"
-               "                         use next line for description when needed"), stdout);
-       fputs(_(" -l, --long-explanation  an example of very verbose, and chatty option\n"
-               "                           description on two, or multiple lines, where the\n"
-               "                           consecutive lines are intended by two spaces"), stdout);
-       fputs(_(" -f, --foobar            next option description resets indent"), stdout);
+       fputsln(_(" -n, --no-argument       option does not use argument"), stdout);
+       fputsln(_("     --optional[=<arg>]  option argument is optional"), stdout);
+       fputsln(_(" -r, --required <arg>    option requires an argument"), stdout);
+       fputsln(_(" -z                      no long option"), stdout);
+       fputsln(_("     --xyzzy             a long option only"), stdout);
+       fputsln(_(" -e, --extremely-long-long-option\n"
+              "                         use next line for description when needed"), stdout);
+       fputsln(_(" -l, --long-explanation  an example of very verbose, and chatty option\n"
+              "                           description on two, or multiple lines, where the\n"
+              "                           consecutive lines are intended by two spaces"), stdout);
+       fputsln(_(" -f, --foobar            next option description resets indent"), stdout);
        fputs(USAGE_SEPARATOR, stdout);
        fprintf(stdout, USAGE_HELP_OPTIONS(25)); /* char offset to align option descriptions */
        fprintf(stdout, USAGE_MAN_TAIL("fixme-command-name(1)"));
index 242d11638a712e973da39d808f1781f28c9c014e..4a1d4e726344bf2cfee14b051e647ab9983e16d0 100644 (file)
@@ -216,17 +216,17 @@ static void __attribute__((__noreturn__)) usage(void)
                ), program_invocation_short_name);
 
        fputs(USAGE_SEPARATOR, stdout);
-       fputs(  _("Call block device ioctls from the command line."), stdout);
+       fputsln(  _("Call block device ioctls from the command line."), stdout);
 
        fputs(USAGE_OPTIONS, stdout);
-       fputs(  _(" -q             quiet mode"), stdout);
-       fputs(  _(" -v             verbose mode"), stdout);
-       fputs(  _("     --report   print report for specified (or all) devices"), stdout);
+       fputsln(  _(" -q             quiet mode"), stdout);
+       fputsln(  _(" -v             verbose mode"), stdout);
+       fputsln(  _("     --report   print report for specified (or all) devices"), stdout);
        fputs(USAGE_SEPARATOR, stdout);
        fprintf(stdout, USAGE_HELP_OPTIONS(16));
 
        fputs(USAGE_SEPARATOR, stdout);
-       fputs(_("Available commands:"), stdout);
+       fputsln(  _("Available commands:"), stdout);
        fprintf(stdout, _(" %-25s get size in 512-byte sectors\n"), "--getsz");
        for (i = 0; i < ARRAY_SIZE(bdcms); i++) {
                if (bdcms[i].argname)
index 840ec8d55867b7b351df58cb86cfc047a0ce0d63..f4ada9052978481b2c5a4945517287f2f75d3bb4 100644 (file)
@@ -131,21 +131,21 @@ static void __attribute__((__noreturn__)) usage(void)
        fprintf(stdout, _(" %s [-h] [-v] [-b blksize] [-e edition] [-N endian] [-i file] [-n name] dirname outfile\n"),
                program_invocation_short_name);
        fputs(USAGE_SEPARATOR, stdout);
-       fputs(_("Make compressed ROM file system."), stdout);
+       fputsln(_("Make compressed ROM file system."), stdout);
        fputs(USAGE_OPTIONS, stdout);
-       fputs(_(  " -v             be verbose"), stdout);
-       fputs(_(  " -E             make all warnings errors (non-zero exit status)"), stdout);
-       fputs(_(  " -b blksize     use this blocksize, must equal page size"), stdout);
-       fputs(_(  " -e edition     set edition number (part of fsid)"), stdout);
+       fputsln(_(  " -v             be verbose"), stdout);
+       fputsln(_(  " -E             make all warnings errors (non-zero exit status)"), stdout);
+       fputsln(_(  " -b blksize     use this blocksize, must equal page size"), stdout);
+       fputsln(_(  " -e edition     set edition number (part of fsid)"), stdout);
        fprintf(stdout, _(" -N endian      set cramfs endianness (%s|%s|%s), default %s\n"), "big", "little", "host", "host");
-       fputs(_(  " -i file        insert a file image into the filesystem"), stdout);
-       fputs(_(  " -n name        set name of cramfs filesystem"), stdout);
+       fputsln(_(  " -i file        insert a file image into the filesystem"), stdout);
+       fputsln(_(  " -n name        set name of cramfs filesystem"), stdout);
        fprintf(stdout, _(" -p             pad by %d bytes for boot code\n"), PAD_SIZE);
-       fputs(_(  " -s             sort directory entries (old option, ignored)"), stdout);
-       fputs(_(  " -z             make explicit holes"), stdout);
-       fputs(_(  " -l[=<mode>]    use exclusive device lock (yes, no or nonblock)"), stdout);
-       fputs(_(  " dirname        root of the filesystem to be compressed"), stdout);
-       fputs(_(  " outfile        output file"), stdout);
+       fputsln(_(  " -s             sort directory entries (old option, ignored)"), stdout);
+       fputsln(_(  " -z             make explicit holes"), stdout);
+       fputsln(_(  " -l[=<mode>]    use exclusive device lock (yes, no or nonblock)"), stdout);
+       fputsln(_(  " dirname        root of the filesystem to be compressed"), stdout);
+       fputsln(_(  " outfile        output file"), stdout);
        fputs(USAGE_SEPARATOR, stdout);
        fprintf(stdout, USAGE_HELP_OPTIONS(16));
        fprintf(stdout, USAGE_MAN_TAIL("mkfs.cramfs(8)"));
index e353643fdd88998f3332165663e7ed03b3e26268..61b95ab2dc5b90e76dbe7b2b3f8e11d76a335432 100644 (file)
@@ -510,6 +510,12 @@ static inline void print_features(const char **features, const char *prefix)
                exit(eval); \
 })
 
+static inline int fputsln(const char *s, FILE *stream) {
+       if (fputs(s, stream) == EOF)
+               return EOF;
+       return fputc('\n', stdout);
+}
+
 /*
  * seek stuff
  */
index 99c831fd90160b1e36e9880403e014d5fcf9936e..48f07aed7bf74cf2a5a5f8d8d9b167bf1ce83f2b 100644 (file)
@@ -67,10 +67,10 @@ static void __attribute__((__noreturn__)) usage(void)
 
        fputs(USAGE_SEPARATOR, stdout);
        /* TRANSLATORS: 'command' refers to a program argument */
-       fputs(_("Set or examine pipe buffer sizes and optionally execute command."), stdout);
+       fputsln(_("Set or examine pipe buffer sizes and optionally execute command."), stdout);
 
        fputs(USAGE_OPTIONS, stdout);
-       fputs(_(" -g, --get          examine pipe buffers"), stdout);
+       fputsln(_(" -g, --get          examine pipe buffers"), stdout);
        /* TRANSLATORS: '%s' refers to a system file */
        fprintf(stdout,
             _(" -s, --set <size>   set pipe buffer sizes\n"
@@ -78,16 +78,16 @@ static void __attribute__((__noreturn__)) usage(void)
                PIPESZ_DEFAULT_SIZE_FILE);
 
        fputs(USAGE_SEPARATOR, stdout);
-       fputs(_(" -f, --file <path>  act on a file"), stdout);
-       fputs(_(" -n, --fd <num>     act on a file descriptor"), stdout);
-       fputs(_(" -i, --stdin        act on standard input"), stdout);
-       fputs(_(" -o, --stdout       act on standard output"), stdout);
-       fputs(_(" -e, --stderr       act on standard error"), stdout);
+       fputsln(_(" -f, --file <path>  act on a file"), stdout);
+       fputsln(_(" -n, --fd <num>     act on a file descriptor"), stdout);
+       fputsln(_(" -i, --stdin        act on standard input"), stdout);
+       fputsln(_(" -o, --stdout       act on standard output"), stdout);
+       fputsln(_(" -e, --stderr       act on standard error"), stdout);
 
        fputs(USAGE_SEPARATOR, stdout);
-       fputs(_(" -c, --check        do not continue after an error"), stdout);
-       fputs(_(" -q, --quiet        do not warn of non-fatal errors"), stdout);
-       fputs(_(" -v, --verbose      provide detailed output"), stdout);
+       fputsln(_(" -c, --check        do not continue after an error"), stdout);
+       fputsln(_(" -q, --quiet        do not warn of non-fatal errors"), stdout);
+       fputsln(_(" -v, --verbose      provide detailed output"), stdout);
 
        fputs(USAGE_SEPARATOR, stdout);
        fprintf(stdout, USAGE_HELP_OPTIONS(20));
index 873b2d4049410895456d2fdaec12a1f255cb8b53..2dd7fb3888ffeb089e6c3f5efe30b7078619badf 100644 (file)
@@ -97,10 +97,10 @@ static void __attribute__((__noreturn__)) usage(void)
        fprintf(stdout, _(" %s [options] <uuid ...>\n"), program_invocation_short_name);
 
        fputs(USAGE_OPTIONS, stdout);
-       fputs(_(" -J, --json             use JSON output format"), stdout);
-       fputs(_(" -n, --noheadings       don't print headings"), stdout);
-       fputs(_(" -o, --output <list>    COLUMNS to display (see below)"), stdout);
-       fputs(_(" -r, --raw              use the raw output format"), stdout);
+       fputsln(_(" -J, --json             use JSON output format"), stdout);
+       fputsln(_(" -n, --noheadings       don't print headings"), stdout);
+       fputsln(_(" -o, --output <list>    COLUMNS to display (see below)"), stdout);
+       fputsln(_(" -r, --raw              use the raw output format"), stdout);
        fprintf(stdout, USAGE_HELP_OPTIONS(24));
 
        fputs(USAGE_COLUMNS, stdout);
index b89006f53b94bc47bc4c152bd90841cb74a8e380..0d6cfa54ee70a724434f45fba77688b85fec84b3 100644 (file)
@@ -630,20 +630,20 @@ usage(void)
        fprintf(stdout, _(" %s [options] <device>\n"), program_invocation_short_name);
 
        fputs(USAGE_SEPARATOR, stdout);
-       fputs(_("Wipe signatures from a device."), stdout);
+       fputsln(_("Wipe signatures from a device."), stdout);
 
        fputs(USAGE_OPTIONS, stdout);
-       fputs(_(" -a, --all            wipe all magic strings (BE CAREFUL!)"), stdout);
-       fputs(_(" -b, --backup[=<dir>] create a signature backup in <dir> or $HOME"), stdout);
-       fputs(_(" -f, --force          force erasure"), stdout);
-       fputs(_(" -i, --noheadings     don't print headings"), stdout);
-       fputs(_(" -J, --json           use JSON output format"), stdout);
-       fputs(_(" -n, --no-act         do everything except the actual write() call"), stdout);
-       fputs(_(" -o, --offset <num>   offset to erase, in bytes"), stdout);
-       fputs(_(" -O, --output <list>  COLUMNS to display (see below)"), stdout);
-       fputs(_(" -p, --parsable       print out in parsable instead of printable format"), stdout);
-       fputs(_(" -q, --quiet          suppress output messages"), stdout);
-       fputs(_(" -t, --types <list>   limit the set of filesystem, RAIDs or partition tables"), stdout);
+       fputsln(_(" -a, --all            wipe all magic strings (BE CAREFUL!)"), stdout);
+       fputsln(_(" -b, --backup[=<dir>] create a signature backup in <dir> or $HOME"), stdout);
+       fputsln(_(" -f, --force          force erasure"), stdout);
+       fputsln(_(" -i, --noheadings     don't print headings"), stdout);
+       fputsln(_(" -J, --json           use JSON output format"), stdout);
+       fputsln(_(" -n, --no-act         do everything except the actual write() call"), stdout);
+       fputsln(_(" -o, --offset <num>   offset to erase, in bytes"), stdout);
+       fputsln(_(" -O, --output <list>  COLUMNS to display (see below)"), stdout);
+       fputsln(_(" -p, --parsable       print out in parsable instead of printable format"), stdout);
+       fputsln(_(" -q, --quiet          suppress output messages"), stdout);
+       fputsln(_(" -t, --types <list>   limit the set of filesystem, RAIDs or partition tables"), stdout);
        fprintf(stdout,
             _("     --lock[=<mode>] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock");
 
index af71a9a4b3a63541e3d1cb092e9a4d6402ec9df4..ca851a49129d67414ae4aea6fd1db47580e73e63 100644 (file)
@@ -1267,16 +1267,16 @@ usage(void)
 
 #ifdef __linux__
        fputs(USAGE_ARGUMENTS, stdout);
-       fputs(_(" <param> is either a numeric RTC parameter value or one of these aliases:"), stdout);
+       fputsln(_(" <param> is either a numeric RTC parameter value or one of these aliases:"), stdout);
 
        while (param->name) {
                fprintf(stdout, _("   - %1$s: %2$s (0x%3$x)\n"), param->name, param->help, param->id);
                param++;
        }
 
-       fputs(_("   See Kernel's include/uapi/linux/rtc.h for parameters and values."), stdout);
+       fputsln(_("   See Kernel's include/uapi/linux/rtc.h for parameters and values."), stdout);
        fputs(USAGE_ARG_SEPARATOR, stdout);
-       fputs(_(" <param> and <value> accept hexadecimal values if prefixed with 0x, otherwise decimal."), stdout);
+       fputsln(_(" <param> and <value> accept hexadecimal values if prefixed with 0x, otherwise decimal."), stdout);
 #endif
        fprintf(stdout, USAGE_MAN_TAIL("hwclock(8)"));
        exit(EXIT_SUCCESS);
index 36164c96bb685d3b0e9fe0bb9d8767e87343038e..2b283d33cd629972a73674d93468a57dd6f98d80 100644 (file)
@@ -50,7 +50,7 @@ static void __attribute__((__noreturn__)) usage(void)
        printf(_(" %s [options]\n"), program_invocation_short_name);
        fputs(USAGE_SEPARATOR, stdout);
 
-       fputs(_("Utility to display kernel interrupt information."), stdout);
+       fputsln(_("Utility to display kernel interrupt information."), stdout);
 
        fputs(USAGE_OPTIONS, stdout);
        fputs(_(" -J, --json           use JSON output format\n"), stdout);