summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2021-09-20 11:54:08 +0100
committerPádraig Brady <P@draigBrady.com>2021-09-20 16:21:15 +0100
commit88b7ff98fe412a32e321d8cc76c896d0fb81c51c (patch)
tree083909123381a62d2a010309d4103c3a6f36c165
parenttests: avoid rare race in tail-2/F-vs-rename.sh (diff)
downloadcoreutils-88b7ff98fe412a32e321d8cc76c896d0fb81c51c.tar.gz
coreutils-88b7ff98fe412a32e321d8cc76c896d0fb81c51c.zip
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.
-rw-r--r--doc/coreutils.texi8
-rw-r--r--src/digest.c17
-rwxr-xr-xtests/misc/cksum-a.sh1
3 files changed, 10 insertions, 16 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 05c5d2e5d..d962d363e 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -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
diff --git a/src/digest.c b/src/digest.c
index 9398a133e..de2decc19 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -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
@@ -453,6 +453,9 @@ Print or check %s (%d-bit) checksums.\n\
# 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);
# else
@@ -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 "
diff --git a/tests/misc/cksum-a.sh b/tests/misc/cksum-a.sh
index 9a58e1c2d..83dde1ff3 100755
--- a/tests/misc/cksum-a.sh
+++ b/tests/misc/cksum-a.sh
@@ -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