cksum: support more transparent emulation of older utils

* src/digest.c: Allow using the --untagged option with --check,
so that `cksum -a md5 --untagged` used to emulate md5sum for example,
may be augmented with the --check option.  Also support the --tag
option with cksum, to allow overriding a previous --untagged setting.
* doc/coreutils.texi: Adjust accordingly.
* tests/misc/cksum-a.sh: Likewise.
This commit is contained in:
Pádraig Brady
2021-09-20 11:54:08 +01:00
parent f80c6c267d
commit 88b7ff98fe
3 changed files with 10 additions and 16 deletions

View File

@@ -3934,8 +3934,9 @@ for each given @var{file}, or standard input if none are given or for a
@var{file} of @samp{-}.
cksum also supports the @option{-a,--algorithm} option to select the
digest algorithm to use, and this is the preferred interface
to these digests, subsuming the other standalone checksumming utilities.
digest algorithm to use. @command{cksum} is the preferred interface
to these digests, subsuming the other standalone checksumming utilities,
which can be emulated using @code{cksum -a md5 --untagged "$@@"} etc.
Synopsis:
@example
@@ -4162,8 +4163,6 @@ indicating there was a failure.
@item --tag
@opindex --tag
@cindex BSD output
Note this option is not supported by the @command{cksum} command,
as this is the default output format that it uses.
Output BSD style checksums, which indicate the checksum algorithm used.
As a GNU extension, if @option{--zero} is not used, file names with problematic
characters are escaped as described above, with the same escaping indicator of
@@ -4171,6 +4170,7 @@ characters are escaped as described above, with the same escaping indicator of
The @option{--tag} option implies binary mode, and is disallowed with
@option{--text} mode as supporting that would unnecessarily complicate
the output format, while providing little benefit.
The @command{cksum} command, uses @option{--tag} as its default output format.
@item -t
@itemx --text

View File

@@ -372,6 +372,7 @@ static struct option const long_options[] =
{ "status", no_argument, NULL, STATUS_OPTION },
{ "warn", no_argument, NULL, 'w' },
{ "strict", no_argument, NULL, STRICT_OPTION },
{ "tag", no_argument, NULL, TAG_OPTION },
{ "zero", no_argument, NULL, 'z' },
# if HASH_ALGO_CKSUM
@@ -381,7 +382,6 @@ static struct option const long_options[] =
# else
{ "binary", no_argument, NULL, 'b' },
{ "text", no_argument, NULL, 't' },
{ "tag", no_argument, NULL, TAG_OPTION },
# endif
#else
@@ -452,6 +452,9 @@ Print or check %s (%d-bit) checksums.\n\
"), stdout);
# endif
# if HASH_ALGO_CKSUM
fputs (_("\
--tag create a BSD-style checksum (the default)\n\
"), stdout);
fputs (_("\
--untagged create a reversed style checksum, without digest type\n\
"), stdout);
@@ -1335,12 +1338,11 @@ main (int argc, char **argv)
case UNTAG_OPTION:
prefix_tag = false;
break;
# else
# endif
case TAG_OPTION:
prefix_tag = true;
binary = 1;
break;
# endif
case 'z':
digest_delim = '\0';
break;
@@ -1421,14 +1423,7 @@ main (int argc, char **argv)
"verifying checksums"));
usage (EXIT_FAILURE);
}
#if HASH_ALGO_CKSUM
if (!prefix_tag && do_check)
{
error (0, 0, _("the --untagged option is meaningless when "
"verifying checksums"));
usage (EXIT_FAILURE);
}
#else
#if !HASH_ALGO_CKSUM
if (prefix_tag && do_check)
{
error (0, 0, _("the --tag option is meaningless when "

View File

@@ -47,7 +47,6 @@ while read algo prog; do
done < input_options
compare out out-a || fail=1
returns_ 1 cksum -a bsd --tag </dev/null || fail=1
returns_ 1 cksum -a bsd --check </dev/null || fail=1
Exit $fail