]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sum,cksum: consistently emit detailed write errors
authorCollin Funk <collin.funk1@gmail.com>
Fri, 1 May 2026 00:59:38 +0000 (17:59 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Fri, 1 May 2026 00:59:38 +0000 (17:59 -0700)
Previously the string from strerror would only be printed for some
algorithms:

    $ cksum -a sha2 -l 256 /dev/null > /dev/full
    cksum: write error: No space left on device
    $ cksum -a sysv /dev/null > /dev/full
    cksum: write error

This patch fixes it so that the error information is always printed:

    $ ./src/cksum -a sha2 -l 256 /dev/null > /dev/full
    cksum: write error: No space left on device
    $ ./src/cksum -a sysv /dev/null > /dev/full
    cksum: write error: No space left on device

* src/cksum.c (output_file): Don't check for a write error here.
(main): Check for it here instead.
* tests/misc/io-errors.sh: Add a 'cksum' invocation for each supported
algorithm.
https://github.com/coreutils/coreutils/issues/258

src/cksum.c
tests/misc/io-errors.sh

index ffd9a82d54878b814e4b920b10474830c168541b..186ba318592d445878bfd693c65207138e57ab9a 100644 (file)
@@ -1317,9 +1317,6 @@ output_file (char const *file, int binary_file, void const *digest,
     }
 
   putchar (delim);
-
-  if (ferror (stdout))
-    write_error ();
 }
 #endif
 
@@ -1885,6 +1882,8 @@ main (int argc, char **argv)
             {
               DIGEST_OUT (file, binary_file, bin_buffer, raw_digest, prefix_tag,
                           digest_delim, optind != argc, length);
+              if (ferror (stdout))
+                write_error ();
             }
         }
     }
index 8b1fcef8fe9c062c7699702394d216e19b50a57a..a7f03a5b2f2259e4eae5b551c9061be39841a48e 100755 (executable)
@@ -34,6 +34,16 @@ echo foo > foo || framework_failure_
 {
 printf '%s' "\
 cat foo
+cksum -a sysv foo
+cksum -a bsd foo
+cksum -a crc foo
+cksum -a crc32b foo
+cksum -a md5 foo
+cksum -a sha1 foo
+cksum -a sha2 -l 256 foo
+cksum -a sha3 -l 256 foo
+cksum -a blake2b foo
+cksum -a sm3 foo
 comm foo foo
 cut -c1- foo
 cut -f1- foo