[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/4] cksum: operate in binary mode only
From: |
Pádraig Brady |
Subject: |
[PATCH 2/4] cksum: operate in binary mode only |
Date: |
Wed, 15 Sep 2021 13:40:34 +0100 |
This only practically matters on windows.
But given there are separate text handling options in cygwin,
keep the interface simple, and avoid exposing the
confusing binary/text difference here.
* doc/coreutils.texi (md5sum invocation): Mention that
--binary and --text are not supported by the cksum command.
* src/digest.c: Set flag to use binary mode by default.
(output_file): Don't distinguish text and binary modes with
' ' and '*', and just use ' ' always.
---
doc/coreutils.texi | 6 +++++-
src/digest.c | 42 ++++++++++++++++++++++++++++--------------
tests/misc/sm3sum.pl | 3 +--
3 files changed, 34 insertions(+), 17 deletions(-)
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index c324dc3ca..68c146ec9 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -4064,7 +4064,8 @@ For each @var{file}, @samp{md5sum} outputs by default,
the MD5 checksum,
a space, a flag indicating binary or text input mode, and the file name.
Binary mode is indicated with @samp{*}, text mode with @samp{ } (space).
Binary mode is the default on systems where it's significant,
-otherwise text mode is the default.
+otherwise text mode is the default. The @command{cksum} command always
+uses binary mode and a @samp{ } (space) flag.
Without @option{--zero}, if @var{file} contains a backslash or newline,
the line is started with a backslash, and each problematic character in
the file name is escaped with a backslash, making the output
@@ -4080,6 +4081,8 @@ The program accepts the following options. Also see
@ref{Common options}.
@opindex -b
@opindex --binary
@cindex binary input files
+Note this option is not supported by the @command{cksum} command,
+as it operates in binary mode exclusively.
Treat each input file as binary, by reading it in binary mode and
outputting a @samp{*} flag. This is the inverse of @option{--text}.
On systems like GNU that do not distinguish between binary
@@ -4168,6 +4171,7 @@ the output format, while providing little benefit.
@opindex -t
@opindex --text
@cindex text input files
+Note this option is not supported by the @command{cksum} command.
Treat each input file as text, by reading it in text mode and
outputting a @samp{ } flag. This is the inverse of @option{--binary}.
This option is the default on systems like GNU that do not
diff --git a/src/digest.c b/src/digest.c
index 71ccc47df..f2a505f24 100644
--- a/src/digest.c
+++ b/src/digest.c
@@ -364,29 +364,30 @@ static struct option const long_options[] =
#if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
{ "length", required_argument, NULL, 'l'},
#endif
+
#if !HASH_ALGO_SUM
- { "binary", no_argument, NULL, 'b' },
{ "check", no_argument, NULL, 'c' },
{ "ignore-missing", no_argument, NULL, IGNORE_MISSING_OPTION},
{ "quiet", no_argument, NULL, QUIET_OPTION },
{ "status", no_argument, NULL, STATUS_OPTION },
- { "text", no_argument, NULL, 't' },
{ "warn", no_argument, NULL, 'w' },
{ "strict", no_argument, NULL, STRICT_OPTION },
+ { "zero", no_argument, NULL, 'z' },
+
# if HASH_ALGO_CKSUM
+ { "algorithm", required_argument, NULL, 'a'},
+ { "debug", no_argument, NULL, DEBUG_PROGRAM_OPTION},
{ "untagged", no_argument, NULL, UNTAG_OPTION },
# else
+ { "binary", no_argument, NULL, 'b' },
+ { "text", no_argument, NULL, 't' },
{ "tag", no_argument, NULL, TAG_OPTION },
# endif
- { "zero", no_argument, NULL, 'z' },
-#endif
-#if HASH_ALGO_CKSUM
- {"algorithm", required_argument, NULL, 'a'},
- {"debug", no_argument, NULL, DEBUG_PROGRAM_OPTION},
-#endif
-#if HASH_ALGO_SUM
+
+#else
{"sysv", no_argument, NULL, 's'},
#endif
+
{ GETOPT_HELP_OPTION_DECL },
{ GETOPT_VERSION_OPTION_DECL },
{ NULL, 0, NULL, 0 }
@@ -430,6 +431,7 @@ Print or check %s (%d-bit) checksums.\n\
"), stdout);
#endif
#if !HASH_ALGO_SUM
+# if !HASH_ALGO_CKSUM
if (O_BINARY)
fputs (_("\
-b, --binary read in binary mode (default unless reading tty
stdin)\n\
@@ -438,7 +440,7 @@ Print or check %s (%d-bit) checksums.\n\
fputs (_("\
-b, --binary read in binary mode\n\
"), stdout);
-
+# endif
fputs (_("\
-c, --check read checksums from the FILEs and check them\n\
"), stdout);
@@ -457,6 +459,7 @@ Print or check %s (%d-bit) checksums.\n\
--tag create a BSD-style checksum\n\
"), stdout);
# endif
+# if !HASH_ALGO_CKSUM
if (O_BINARY)
fputs (_("\
-t, --text read in text mode (default if reading tty stdin)\n\
@@ -465,6 +468,7 @@ Print or check %s (%d-bit) checksums.\n\
fputs (_("\
-t, --text read in text mode (default)\n\
"), stdout);
+# endif
fputs (_("\
-z, --zero end each output line with NUL, not newline,\n\
and disable file name escaping\n\
@@ -991,7 +995,12 @@ output_file (char const *file, int binary_file, void const
*digest,
{
putchar (' ');
+# if HASH_ALGO_CKSUM
+ /* Simplify output as always in binary mode. */
+ putchar (' ');
+# else
putchar (binary_file ? '*' : ' ');
+# endif
print_filename (file, needs_escape);
}
@@ -1220,10 +1229,11 @@ main (int argc, char **argv)
bool do_check = false;
int opt;
bool ok = true;
- int binary = -1;
#if HASH_ALGO_CKSUM
+ int binary = 1;
bool prefix_tag = true;
#else
+ int binary = -1;
bool prefix_tag = false;
#endif
@@ -1279,9 +1289,6 @@ main (int argc, char **argv)
break;
#endif
#if !HASH_ALGO_SUM
- case 'b':
- binary = 1;
- break;
case 'c':
do_check = true;
break;
@@ -1290,9 +1297,14 @@ main (int argc, char **argv)
warn = false;
quiet = false;
break;
+# if !HASH_ALGO_CKSUM
+ case 'b':
+ binary = 1;
+ break;
case 't':
binary = 0;
break;
+# endif
case 'w':
status_only = false;
warn = true;
@@ -1415,12 +1427,14 @@ main (int argc, char **argv)
}
#endif
+#if !HASH_ALGO_CKSUM
if (0 <= binary && do_check)
{
error (0, 0, _("the --binary and --text options are meaningless when "
"verifying checksums"));
usage (EXIT_FAILURE);
}
+#endif
if (ignore_missing && !do_check)
{
diff --git a/tests/misc/sm3sum.pl b/tests/misc/sm3sum.pl
index 91cce6505..6c84d6b3b 100755
--- a/tests/misc/sm3sum.pl
+++ b/tests/misc/sm3sum.pl
@@ -41,11 +41,10 @@ my @Tests =
{OUT=>"c8aaf89429554029e231941a2acc0ad61ff2a5acd8fadd25847a3a732b3b02c3
f\n"}],
);
-# Insert the '--text' argument for each test.
+# Insert the arguments for each test.
my $t;
foreach $t (@Tests)
{
- splice @$t, 1, 0, '--text' unless @$t[1] =~ /--check/;
splice @$t, 1, 0, '--untagged -a sm3'
}
--
2.26.2
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], (continued)
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Pádraig Brady, 2021/09/12
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Pádraig Brady, 2021/09/14
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Jim Meyering, 2021/09/14
- [PATCH 3/4] doc: improve --help indenting in checksum utils, Pádraig Brady, 2021/09/15
- [PATCH 1/4] cksum: use --tag format by default, Pádraig Brady, 2021/09/15
- Re: [PATCH 1/4] cksum: use --tag format by default, Eric Blake, 2021/09/17
- Re: [PATCH 1/4] cksum: use --tag format by default, Pádraig Brady, 2021/09/17
- Re: [PATCH 1/4] cksum: use --tag format by default, Pádraig Brady, 2021/09/20
- [PATCH 4/4] digest: support windows format checksum files, Pádraig Brady, 2021/09/15
- Re: [PATCH 4/4] digest: support windows format checksum files, Eric Blake, 2021/09/17
- [PATCH 2/4] cksum: operate in binary mode only,
Pádraig Brady <=
- Re: [PATCH V2] Add support for cksum --algorithm [sm3], Eric Blake, 2021/09/17