]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: support more transparent emulation of older utils
authorPádraig Brady <P@draigBrady.com>
Mon, 20 Sep 2021 10:54:08 +0000 (11:54 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 20 Sep 2021 15:21:15 +0000 (16:21 +0100)
* 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.

doc/coreutils.texi
src/digest.c
tests/misc/cksum-a.sh

index 05c5d2e5d963a7ba9f6372db4124e3efb433b07c..d962d363e93bc96b10905b4fce0904ec7afa9c53 100644 (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
index 9398a133ecf5bb251de47ffb1ab096d62cc3336c..de2decc19ced4d09e586b7b0c999bda56b5c0d2f 100644 (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 "
index 9a58e1c2d305ac74b38b0eb274fb8d904da41450..83dde1ff35fdfd16f1dc34ca0e98d29d253ddb56 100755 (executable)
@@ -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