]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cksum: support --zero in default mode
authorPádraig Brady <P@draigBrady.com>
Sun, 12 Sep 2021 15:57:12 +0000 (16:57 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Sep 2021 19:44:18 +0000 (20:44 +0100)
* src/cksum.h: Thread DELIM through the output functions.
* src/digest.c: Likewise.
* src/sum.c: Likewise.
* src/sum.h: Likewise.
* src/cksum.c: Likewise. Also adjust check to allow -z
with traditional output modes.  Also ajust the global variable
name to avoid shadowing warnings.
* tests/misc/cksum-a.sh: Adjust accordingly.

src/cksum.c
src/cksum.h
src/digest.c
src/sum.c
src/sum.h
tests/misc/cksum-a.sh

index 01549ecffb4daf4341931cfb1033f75383bcb47a..116d23f8009ae32331ee148f3d3d2bc53f6a2339 100644 (file)
@@ -285,13 +285,14 @@ crc_sum_stream (FILE *stream, void *resstream, uintmax_t *length)
 
 void
 output_crc (char const *file, int binary_file, void const *digest,
-            bool tagged, bool args _GL_UNUSED, uintmax_t length _GL_UNUSED)
+            bool tagged, unsigned char delim, bool args _GL_UNUSED,
+            uintmax_t length _GL_UNUSED)
 {
   char length_buf[INT_BUFSIZE_BOUND (uintmax_t)];
   printf ("%u %s", *(unsigned int *)digest, umaxtostr (length, length_buf));
   if (args)
     printf (" %s", file);
-  putchar ('\n');
+  putchar (delim);
 }
 
 #endif /* !CRCTAB */
index e059965ff3de6ce3451b9fa1d260dc75c0f38338..6310c710928d65b3e1606c95bb11218229561705 100644 (file)
@@ -8,7 +8,8 @@ crc_sum_stream (FILE *stream, void *resstream, uintmax_t *length);
 
 extern void
 output_crc (char const *file, int binary_file, void const *digest,
-            bool tagged, bool args _GL_UNUSED, uintmax_t length _GL_UNUSED);
+            bool tagged, unsigned char delim, bool args _GL_UNUSED,
+            uintmax_t length _GL_UNUSED);
 
 extern bool
 cksum_pclmul (FILE *fp, uint_fast32_t *crc_out, uintmax_t *length_out);
index 2150b487dde4076f01ea7c6a4c3ed57d8407429c..e841bbb8425085747db349b5314499629356d4ef 100644 (file)
 #if !HASH_ALGO_SUM
 static void
 output_file (char const *file, int binary_file, void const *digest,
-             bool tagged, bool args _GL_UNUSED, uintmax_t length _GL_UNUSED);
+             bool tagged, unsigned char delim, bool args _GL_UNUSED,
+             uintmax_t length _GL_UNUSED);
 #endif
 
 /* True if any of the files read were the standard input. */
@@ -199,7 +200,7 @@ static bool strict = false;
 static int bsd_reversed = -1;
 
 /* line delimiter.  */
-static unsigned char delim = '\n';
+static unsigned char digest_delim = '\n';
 
 #if HASH_ALGO_BLAKE2 || HASH_ALGO_CKSUM
 # define BLAKE2B_MAX_LEN BLAKE2B_OUTBYTES
@@ -207,7 +208,7 @@ static uintmax_t digest_length;
 #endif /* HASH_ALGO_BLAKE2 */
 
 typedef void (*digest_output_fn)(char const*, int, void const*,
-                                 bool, bool, uintmax_t);
+                                 bool, unsigned char, bool, uintmax_t);
 #if HASH_ALGO_SUM
 enum Algorithm
 {
@@ -933,7 +934,8 @@ digest_file (char const *filename, int *binary, unsigned char *bin_result,
 #if !HASH_ALGO_SUM
 static void
 output_file (char const *file, int binary_file, void const *digest,
-             bool tagged, bool args _GL_UNUSED, uintmax_t length _GL_UNUSED)
+             bool tagged, unsigned char delim, bool args _GL_UNUSED,
+             uintmax_t length _GL_UNUSED)
 {
   unsigned char const *bin_buffer = digest;
   /* We don't really need to escape, and hence detect, the '\\'
@@ -1298,7 +1300,7 @@ main (int argc, char **argv)
         binary = 1;
         break;
       case 'z':
-        delim = '\0';
+        digest_delim = '\0';
         break;
 #endif
 #if HASH_ALGO_SUM
@@ -1350,9 +1352,6 @@ main (int argc, char **argv)
     case bsd:
     case sysv:
     case crc:
-        if (delim != '\n')
-          die (EXIT_FAILURE, 0,
-              _("--zero is not supported with --algorithm={bsd,sysv,crc}"));
         if (prefix_tag)
           die (EXIT_FAILURE, 0,
               _("--tag is not supported with --algorithm={bsd,sysv,crc}"));
@@ -1377,7 +1376,7 @@ main (int argc, char **argv)
      usage (EXIT_FAILURE);
    }
 
-  if (delim != '\n' && do_check)
+  if (digest_delim != '\n' && do_check)
     {
       error (0, 0, _("the --zero option is not supported when "
                      "verifying checksums"));
@@ -1457,7 +1456,7 @@ main (int argc, char **argv)
           else
             {
               DIGEST_OUT (file, binary_file, bin_buffer, prefix_tag,
-                          optind != argc, length);
+                          digest_delim, optind != argc, length);
             }
         }
     }
index 4e1efe9e1178f6e1f3d823fd732b26918af3ba68..3c5e687db59416e01debe4f9ef1be444481495cb 100644 (file)
--- a/src/sum.c
+++ b/src/sum.c
@@ -184,7 +184,8 @@ cleanup_buffer:
 
 void
 output_bsd (char const *file, int binary_file, void const *digest,
-            bool tagged, bool args _GL_UNUSED, uintmax_t length _GL_UNUSED)
+            bool tagged, unsigned char delim, bool args _GL_UNUSED,
+            uintmax_t length _GL_UNUSED)
 {
 
   char hbuf[LONGEST_HUMAN_READABLE + 1];
@@ -192,7 +193,7 @@ output_bsd (char const *file, int binary_file, void const *digest,
           human_readable (length, hbuf, human_ceiling, 1, 1024));
   if (args)
     printf (" %s", file);
-  putchar ('\n');
+  putchar (delim);
 }
 
 /* Print the checksum and size (in 512 byte blocks) to stdout.
@@ -200,7 +201,8 @@ output_bsd (char const *file, int binary_file, void const *digest,
 
 void
 output_sysv (char const *file, int binary_file, void const *digest,
-             bool tagged, bool args _GL_UNUSED, uintmax_t length _GL_UNUSED)
+             bool tagged, unsigned char delim, bool args _GL_UNUSED,
+             uintmax_t length _GL_UNUSED)
 {
 
   char hbuf[LONGEST_HUMAN_READABLE + 1];
@@ -208,5 +210,5 @@ output_sysv (char const *file, int binary_file, void const *digest,
           human_readable (length, hbuf, human_ceiling, 1, 512));
   if (args)
     printf (" %s", file);
-  putchar ('\n');
+  putchar (delim);
 }
index ca68f750a2d874c7c117aaede836a34a3cd9b58c..1681697aba4573df488f64b8f446bfbe00654364 100644 (file)
--- a/src/sum.h
+++ b/src/sum.h
@@ -9,8 +9,10 @@ typedef int (*sumfn)(FILE *, void *, uintmax_t*);
 
 extern void
 output_bsd (char const *file, int binary_file, void const *digest,
-            bool tagged, bool args _GL_UNUSED, uintmax_t length _GL_UNUSED);
+            bool tagged, unsigned char delim, bool args _GL_UNUSED,
+            uintmax_t length _GL_UNUSED);
 
 extern void
 output_sysv (char const *file, int binary_file, void const *digest,
-             bool tagged, bool args _GL_UNUSED, uintmax_t length _GL_UNUSED);
+             bool tagged, unsigned char delim, bool args _GL_UNUSED,
+             uintmax_t length _GL_UNUSED);
index 7d95b69a448f2be7a89a0be69aaf44515478a632..8c4b32551b15e28dcc69b37d54146635f0f8501f 100755 (executable)
@@ -37,7 +37,6 @@ done
 compare out out-a || fail=1
 
 returns_ 1 cksum -a bsd --tag </dev/null
-returns_ 1 cksum -a bsd --zero </dev/null
 returns_ 1 cksum -a bsd --check </dev/null
 
 Exit $fail