]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: operate in binary mode only
authorPádraig Brady <P@draigBrady.com>
Mon, 13 Sep 2021 14:24:24 +0000 (15:24 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Sep 2021 19:44:18 +0000 (20:44 +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
src/digest.c
tests/misc/sm3sum.pl

index 68bc4470a43e49a925967e810ad32462f1af3fdf..bf640e387cd6df6d6fc85b8bfbe36031a5180737 100644 (file)
@@ -4066,7 +4066,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
@@ -4082,6 +4083,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
@@ -4172,6 +4175,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
index 467cba88000198dbd40487235119f226d53e0eef..d8c43c0254fa2300d636c3558bdccb36d3ecc176 100644 (file)
@@ -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 }
@@ -431,6 +432,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\
@@ -439,7 +441,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);
@@ -458,6 +460,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\
@@ -466,6 +469,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\
@@ -992,7 +996,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);
     }
@@ -1221,10 +1230,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
 
@@ -1280,9 +1290,6 @@ main (int argc, char **argv)
         break;
 #endif
 #if !HASH_ALGO_SUM
-      case 'b':
-        binary = 1;
-        break;
       case 'c':
         do_check = true;
         break;
@@ -1291,9 +1298,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;
@@ -1416,12 +1428,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)
     {
index 91cce6505fb2cc32bc607c088f268e1282619c70..6c84d6b3b79056fc5b57352ce588496619e45dac 100755 (executable)
@@ -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'
   }