sum,cksum: consistently emit detailed write errors

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
This commit is contained in:
Collin Funk
2026-04-30 17:59:38 -07:00
parent 578b2cd375
commit 2de1a28bcf
2 changed files with 12 additions and 3 deletions
+2 -3
View 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 ();
}
}
}
+10
View File
@@ -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