From: Pádraig Brady
Date: Mon, 20 Sep 2021 10:54:08 +0000 (+0100) Subject: cksum: support more transparent emulation of older utils X-Git-Tag: v9.0~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88b7ff98fe412a32e321d8cc76c896d0fb81c51c;p=thirdparty%2Fcoreutils.git 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. --- diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 05c5d2e5d9..d962d363e9 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 9398a133ec..de2decc19c 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 @@ -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 " diff --git a/tests/misc/cksum-a.sh b/tests/misc/cksum-a.sh index 9a58e1c2d3..83dde1ff35 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