From: Thomas Weißschuh Date: Tue, 23 Jan 2024 19:22:21 +0000 (+0100) Subject: treewide: fix newlines when using fputs X-Git-Tag: v2.40-rc1~20^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f11785b5d50e3440261d01c98d7c580b5ca8975c;p=thirdparty%2Futil-linux.git treewide: fix newlines when using fputs 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. --- diff --git a/Documentation/boilerplate.c b/Documentation/boilerplate.c index 95915b5ccf..4fc4383dac 100644 --- a/Documentation/boilerplate.c +++ b/Documentation/boilerplate.c @@ -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[=] option argument is optional"), stdout); - fputs(_(" -r, --required 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[=] option argument is optional"), stdout); + fputsln(_(" -r, --required 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)")); diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c index 242d11638a..4a1d4e7263 100644 --- a/disk-utils/blockdev.c +++ b/disk-utils/blockdev.c @@ -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) diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c index 840ec8d558..f4ada90529 100644 --- a/disk-utils/mkfs.cramfs.c +++ b/disk-utils/mkfs.cramfs.c @@ -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[=] 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[=] 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)")); diff --git a/include/c.h b/include/c.h index e353643fdd..61b95ab2dc 100644 --- a/include/c.h +++ b/include/c.h @@ -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 */ diff --git a/misc-utils/pipesz.c b/misc-utils/pipesz.c index 99c831fd90..48f07aed7b 100644 --- a/misc-utils/pipesz.c +++ b/misc-utils/pipesz.c @@ -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 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 act on a file"), stdout); - fputs(_(" -n, --fd 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 act on a file"), stdout); + fputsln(_(" -n, --fd 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)); diff --git a/misc-utils/uuidparse.c b/misc-utils/uuidparse.c index 873b2d4049..2dd7fb3888 100644 --- a/misc-utils/uuidparse.c +++ b/misc-utils/uuidparse.c @@ -97,10 +97,10 @@ static void __attribute__((__noreturn__)) usage(void) fprintf(stdout, _(" %s [options] \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 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 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); diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index b89006f53b..0d6cfa54ee 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -630,20 +630,20 @@ usage(void) fprintf(stdout, _(" %s [options] \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[=] create a signature backup in 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 offset to erase, in bytes"), stdout); - fputs(_(" -O, --output 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 limit the set of filesystem, RAIDs or partition tables"), stdout); + fputsln(_(" -a, --all wipe all magic strings (BE CAREFUL!)"), stdout); + fputsln(_(" -b, --backup[=] create a signature backup in 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 offset to erase, in bytes"), stdout); + fputsln(_(" -O, --output 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 limit the set of filesystem, RAIDs or partition tables"), stdout); fprintf(stdout, _(" --lock[=] use exclusive device lock (%s, %s or %s)\n"), "yes", "no", "nonblock"); diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c index af71a9a4b3..ca851a4912 100644 --- a/sys-utils/hwclock.c +++ b/sys-utils/hwclock.c @@ -1267,16 +1267,16 @@ usage(void) #ifdef __linux__ fputs(USAGE_ARGUMENTS, stdout); - fputs(_(" is either a numeric RTC parameter value or one of these aliases:"), stdout); + fputsln(_(" 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(_(" and accept hexadecimal values if prefixed with 0x, otherwise decimal."), stdout); + fputsln(_(" and accept hexadecimal values if prefixed with 0x, otherwise decimal."), stdout); #endif fprintf(stdout, USAGE_MAN_TAIL("hwclock(8)")); exit(EXIT_SUCCESS); diff --git a/sys-utils/lsirq.c b/sys-utils/lsirq.c index 36164c96bb..2b283d33cd 100644 --- a/sys-utils/lsirq.c +++ b/sys-utils/lsirq.c @@ -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);