Change calls to error_msg.* and strerror to use perror_msg.*.
[oweals/busybox.git] / coreutils / md5sum.c
index 30b882ab55d8e29f56187344a07a7fe86d7c55bf..ecc1458a2a4a4652ab9bf47853e71db89b243454 100644 (file)
@@ -107,48 +107,8 @@ extern _IO_ssize_t getline __P ((char **, size_t *, FILE *));
    the resulting executable.  Locally running cross-compiled executables
    is usually not possible.  */
 
-#ifdef _LIBC
 # include <sys/types.h>
 typedef u_int32_t md5_uint32;
-#else
-# if defined __STDC__ && __STDC__
-#  define UINT_MAX_32_BITS 4294967295U
-# else
-#  define UINT_MAX_32_BITS 0xFFFFFFFF
-# endif
-
-/* If UINT_MAX isn't defined, assume it's a 32-bit type.
-   This should be valid for all systems GNU cares about because
-   that doesn't include 16-bit systems, and only modern systems
-   (that certainly have <limits.h>) have 64+-bit integral types.  */
-
-# ifndef UINT_MAX
-#  define UINT_MAX UINT_MAX_32_BITS
-# endif
-
-# if UINT_MAX == UINT_MAX_32_BITS
-   typedef unsigned int md5_uint32;
-# else
-#  if USHRT_MAX == UINT_MAX_32_BITS
-    typedef unsigned short md5_uint32;
-#  else
-#   if ULONG_MAX == UINT_MAX_32_BITS
-     typedef unsigned long md5_uint32;
-#   else
-     /* The following line is intended to evoke an error.
-        Using #error is not portable enough.  */
-     "Cannot determine unsigned 32-bit data type."
-#   endif
-#  endif
-# endif
-#endif
-
-#undef __P
-#if defined (__STDC__) && __STDC__
-#define        __P(x) x
-#else
-#define        __P(x) ()
-#endif
 
 /* Structure to save state of computation between the single steps.  */
 struct md5_ctx
@@ -691,13 +651,13 @@ static int md5_file(const char *filename,
   } else {
     fp = fopen(filename, OPENOPTS(binary));
     if (fp == NULL) {
-      errorMsg("%s: %s\n", filename, strerror(errno));
+      perror_msg("%s", filename);
       return FALSE;
     }
   }
 
   if (md5_stream(fp, md5_result)) {
-    errorMsg("%s: %s\n", filename, strerror(errno));
+    perror_msg("%s", filename);
 
     if (fp != stdin)
       fclose(fp);
@@ -705,7 +665,7 @@ static int md5_file(const char *filename,
   }
 
   if (fp != stdin && fclose(fp) == EOF) {
-    errorMsg("%s: %s\n", filename, strerror(errno));
+    perror_msg("%s", filename);
     return FALSE;
   }
 
@@ -729,7 +689,7 @@ static int md5_check(const char *checkfile_name)
   } else {
     checkfile_stream = fopen(checkfile_name, "r");
     if (checkfile_stream == NULL) {
-      errorMsg("%s: %s\n", checkfile_name, strerror(errno));
+      perror_msg("%s", checkfile_name);
       return FALSE;
     }
   }
@@ -762,7 +722,7 @@ static int md5_check(const char *checkfile_name)
     if (split_3(line, line_length, &md5num, &binary, &filename)
         || !hex_digits(md5num)) {
       if (warn) {
-        errorMsg("%s: %lu: improperly formatted MD5 checksum line\n",
+        error_msg("%s: %lu: improperly formatted MD5 checksum line\n",
                  checkfile_name, (unsigned long) line_number);
       }
     } else {
@@ -810,18 +770,18 @@ static int md5_check(const char *checkfile_name)
     free(line);
 
   if (ferror(checkfile_stream)) {
-    errorMsg("%s: read error\n", checkfile_name); /* */
+    error_msg("%s: read error\n", checkfile_name); /* */
     return FALSE;
   }
 
   if (checkfile_stream != stdin && fclose(checkfile_stream) == EOF) {
-    errorMsg("md5sum: %s: %s\n", checkfile_name, strerror(errno));
+    perror_msg("md5sum: %s", checkfile_name);
     return FALSE;
   }
 
   if (n_properly_formated_lines == 0) {
     /* Warn if no tests are found.  */
-    errorMsg("%s: no properly formatted MD5 checksum lines found\n",
+    error_msg("%s: no properly formatted MD5 checksum lines found\n",
              checkfile_name);
     return FALSE;
   } else {
@@ -830,13 +790,13 @@ static int md5_check(const char *checkfile_name)
                                  - n_open_or_read_failures);
 
       if (n_open_or_read_failures > 0) {
-        errorMsg("WARNING: %d of %d listed files could not be read\n",
+        error_msg("WARNING: %d of %d listed files could not be read\n",
                  n_open_or_read_failures, n_properly_formated_lines);
         return FALSE;
       }
 
       if (n_mismatched_checksums > 0) {
-        errorMsg("WARNING: %d of %d computed checksums did NOT match\n",
+        error_msg("WARNING: %d of %d computed checksums did NOT match\n",
                  n_mismatched_checksums, n_computed_checkums);
         return FALSE;
       }
@@ -901,22 +861,22 @@ int md5sum_main(int argc,
   }
 
   if (file_type_specified && do_check) {
-    errorMsg("the -b and -t options are meaningless when verifying checksums\n");
+    error_msg("the -b and -t options are meaningless when verifying checksums\n");
        return EXIT_FAILURE;
   }
 
   if (n_strings > 0 && do_check) {
-    errorMsg("the -g and -c options are mutually exclusive\n");
+    error_msg("the -g and -c options are mutually exclusive\n");
        return EXIT_FAILURE;
   }
 
   if (status_only && !do_check) {
-    errorMsg("the -s option is meaningful only when verifying checksums\n");
+    error_msg("the -s option is meaningful only when verifying checksums\n");
        return EXIT_FAILURE;
   }
 
   if (warn && !do_check) {
-    errorMsg("the -w option is meaningful only when verifying checksums\n");
+    error_msg("the -w option is meaningful only when verifying checksums\n");
        return EXIT_FAILURE;
   }
 
@@ -924,7 +884,7 @@ int md5sum_main(int argc,
     size_t i;
 
     if (optind < argc) {
-      errorMsg("no files may be specified when using -g\n");
+      error_msg("no files may be specified when using -g\n");
          return EXIT_FAILURE;
     }
     for (i = 0; i < n_strings; ++i) {
@@ -938,7 +898,7 @@ int md5sum_main(int argc,
     }
   } else if (do_check) {
     if (optind + 1 < argc) {
-      errorMsg("only one argument may be specified when using -c\n");
+      error_msg("only one argument may be specified when using -c\n");
     }
 
     err = md5_check ((optind == argc) ? "-" : argv[optind]);
@@ -991,12 +951,12 @@ int md5sum_main(int argc,
   }
 
   if (fclose (stdout) == EOF) {
-    errorMsg("write error\n");
+    error_msg("write error\n");
        return EXIT_FAILURE;
   }
 
   if (have_read_stdin && fclose (stdin) == EOF) {
-    errorMsg("standard input\n");
+    error_msg("standard input\n");
        return EXIT_FAILURE;
   }