]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sum: always output a file name if one passed
authorPádraig Brady <P@draigBrady.com>
Sun, 29 Aug 2021 19:57:33 +0000 (20:57 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 31 Aug 2021 10:33:26 +0000 (11:33 +0100)
Adjust to output the file name if any name parameter is passed.
This is consistent with sum -s, cksum, and sum implementations
on other platforms.  This should not cause significant compat
issues, as multiple fields are already output, and so already
need to be parsed.

* src/sum.c (bsd_sum_file): Output the file name
if any name parameter is passed.
* tests/misc/sum.pl: Adjust accordingly.
* doc/coreutils.texi (sum invocation): Likewise.
* NEWS: Mention the change in behavior.

NEWS
doc/coreutils.texi
src/sum.c
tests/misc/sum.pl

diff --git a/NEWS b/NEWS
index efdb1450e1c20feda1c0f317528d93451a3b0f30..d9ab04529ac39e3425a4add1a0aee355961f0aeb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -83,6 +83,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   stat will use decomposed (major,minor) device numbers in its default format.
   This is less ambiguous, and more consistent with ls.
 
+  sum [-r] will output a file name, even if only a single name is passed.
+  This is consistent with sum -s, cksum, and other sum(1) implementations.
+
 ** New Features
 
   expr and factor now support bignums on all platforms.
index a435ed63e86739308c3ce689184cd67f36cdcdc2..5c12298cfe1f654e87ecc7402ac261b13f2b22d2 100644 (file)
@@ -3887,10 +3887,8 @@ sum [@var{option}]@dots{} [@var{file}]@dots{}
 @end example
 
 @command{sum} prints the checksum for each @var{file} followed by the
-number of blocks in the file (rounded up).  If more than one @var{file}
-is given, file names are also printed (by default).  (With the
-@option{--sysv} option, corresponding file names are printed when there is
-at least one file argument.)
+number of blocks in the file (rounded up).  If at least one @var{file}
+is given, file names are also printed.
 
 By default, GNU @command{sum} computes checksums using an algorithm
 compatible with BSD @command{sum} and prints file sizes in units of
index c17af3f6b3ddcbc857a7b47379cfd7896017e654..018623d4783e29138b97f292e75e41d3fd08afbe 100644 (file)
--- a/src/sum.c
+++ b/src/sum.c
@@ -80,7 +80,7 @@ Print checksum and block counts for each FILE.\n\
 
 /* Calculate and print the rotated checksum and the size in 1K blocks
    of file FILE, or of the standard input if FILE is "-".
-   If PRINT_NAME is >1, print FILE next to the checksum and size.
+   If PRINT_NAME is >0, print FILE next to the checksum and size.
    The checksum varies depending on sizeof (int).
    Return true if successful.  */
 
@@ -135,7 +135,7 @@ bsd_sum_file (char const *file, int print_name)
 
   printf ("%05d %5s", checksum,
           human_readable (total_bytes, hbuf, human_ceiling, 1, 1024));
-  if (print_name > 1)
+  if (print_name)
     printf (" %s", file);
   putchar ('\n');
 
index 0b737c4e6959df9891b5942b22216a76b4bc0bf1..0b0f88189237a4d32776aec8b3fecccdd3dd739a 100755 (executable)
@@ -28,18 +28,18 @@ my $in_2k = 'b' x 2048;
 
 my @Tests =
     (
-     ['1', {IN=> {f=> ''}},    {OUT=>"00000     0\n"}],
-     ['2', {IN=> {f=> 'a'}},   {OUT=>"00097     1\n"}],
-     ['3', {IN=> {f=> 'abc'}}, {OUT=>"16556     1\n"}],
-     ['4', {IN=> {f=> 'message digest'}}, {OUT=>"26423     1\n"}],
-     ['5', {IN=> {f=> 'abcdefghijklmnopqrstuvwxyz'}}, {OUT=>"53553     1\n"}],
+     ['1', {IN=> {f=> ''}},    {OUT=>"00000     0 f\n"}],
+     ['2', {IN=> {f=> 'a'}},   {OUT=>"00097     1 f\n"}],
+     ['3', {IN=> {f=> 'abc'}}, {OUT=>"16556     1 f\n"}],
+     ['4', {IN=> {f=> 'message digest'}}, {OUT=>"26423     1 f\n"}],
+     ['5', {IN=> {f=> 'abcdefghijklmnopqrstuvwxyz'}}, {OUT=>"53553     1 f\n"}],
      ['6', {IN=> {f=> join ('', 'A'..'Z', 'a'..'z', '0'..'9')}},
-                                {OUT=>"25587     1\n"}],
-     ['7', {IN=> {f=> '1234567890' x 8}}, {OUT=>"21845     1\n"}],
+                                {OUT=>"25587     1 f\n"}],
+     ['7', {IN=> {f=> '1234567890' x 8}}, {OUT=>"21845     1 f\n"}],
 
-     ['a-r-1k', '-r', {IN=> {f=> $in_1k}}, {OUT=>"65409     1\n"}],
+     ['a-r-1k', '-r', {IN=> {f=> $in_1k}}, {OUT=>"65409     1 f\n"}],
      ['a-s-1k', '-s', {IN=> {f=> $in_1k}}, {OUT=>"33793 2 f\n"}],
-     ['b-r-2k', '-r', {IN=> {f=> $in_2k}}, {OUT=>"65223     2\n"}],
+     ['b-r-2k', '-r', {IN=> {f=> $in_2k}}, {OUT=>"65223     2 f\n"}],
      ['b-s-2k', '-s', {IN=> {f=> $in_2k}}, {OUT=>"4099 4 f\n"}],
 
      ['1s', '-s', {IN=> {f=> ''}},     {OUT=>"0 0 f\n"}],