]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(md5_check): Remove parameter, BINARY.
authorJim Meyering <jim@meyering.net>
Fri, 26 Jul 1996 04:11:21 +0000 (04:11 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 26 Jul 1996 04:11:21 +0000 (04:11 +0000)
Rename local TYPE_FLAG to BINARY, so md5_file uses the binary mode
from the input stream rather than the one from the command line.
(main): Fail with a diagnostic if --binary or --text is specified
when verifying checksums.
Reported by Eli Zaretskii <eliz@is.elta.co.il>.

src/md5sum.c

index daae484c72c0aa7a9d7f7beba2bd76c75a8737c4..cbc66a3886d1705d3364ce00b946be96b4cb7f99 100644 (file)
@@ -278,7 +278,7 @@ md5_file (const char *filename, int binary, unsigned char *md5_result)
 }
 
 static int
-md5_check (const char *checkfile_name, int binary)
+md5_check (const char *checkfile_name)
 {
   FILE *checkfile_stream;
   int n_properly_formated_lines = 0;
@@ -311,7 +311,7 @@ md5_check (const char *checkfile_name, int binary)
   do
     {
       char *filename;
-      int type_flag;
+      int binary;
       char *md5num;
       int err;
       int line_length;
@@ -330,7 +330,7 @@ md5_check (const char *checkfile_name, int binary)
       if (line[line_length - 1] == '\n')
        line[--line_length] = '\0';
 
-      err = split_3 (line, line_length, &md5num, &type_flag, &filename);
+      err = split_3 (line, line_length, &md5num, &binary, &filename);
       if (err || !hex_digits (md5num))
        {
          if (warn)
@@ -450,6 +450,7 @@ main (int argc, char **argv)
   size_t n_strings = 0;
   size_t i;
   size_t err = 0;
+  int file_type_specified = 0;
 
   /* Text is default of the Plumb/Lankester format.  */
   int binary = 0;
@@ -479,6 +480,7 @@ main (int argc, char **argv)
        }
        break;
       case 'b':
+       file_type_specified = 1;
        binary = 1;
        break;
       case 'c':
@@ -489,6 +491,7 @@ main (int argc, char **argv)
        warn = 0;
        break;
       case 't':
+       file_type_specified = 1;
        binary = 0;
        break;
       case 'w':
@@ -505,6 +508,13 @@ main (int argc, char **argv)
       exit (EXIT_SUCCESS);
     }
 
+  if (file_type_specified && do_check)
+    {
+      error (0, 0, _("the --binary and --text options are meaningless when \
+verifying checksums"));
+      usage (EXIT_FAILURE);
+    }
+
   if (n_strings > 0 && do_check)
     {
       error (0, 0,
@@ -553,7 +563,7 @@ main (int argc, char **argv)
          usage (EXIT_FAILURE);
        }
 
-      err = md5_check ((optind == argc) ? "-" : argv[optind], binary);
+      err = md5_check ((optind == argc) ? "-" : argv[optind]);
     }
   else
     {