Remove #ifdef __STDC__ junk. We don't do K&R round these parts,
[oweals/busybox.git] / md5sum.c
index f4a8b99d0018065fb38fcf614976eaa0558918e5..84e037a612f7b6cf54d7bead86bc9954f04fc767 100644 (file)
--- a/md5sum.c
+++ b/md5sum.c
@@ -20,7 +20,7 @@
 /* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu> */
 /* Hacked to work with BusyBox by Alfred M. Szmidt <ams@trillian.itslinux.org> */
 
-#include "internal.h"
+#include "busybox.h"
 #include <stdio.h>
 #include <errno.h>
 #include <ctype.h>
@@ -66,7 +66,7 @@ extern _IO_ssize_t getline __P ((char **, size_t *, FILE *));
 #include <string.h>
 #include <endian.h>
 
-#include "internal.h"
+#include "busybox.h"
 //----------------------------------------------------------------------------
 //--------md5.h
 //----------------------------------------------------------------------------
@@ -96,7 +96,7 @@ extern _IO_ssize_t getline __P ((char **, size_t *, FILE *));
 
 #include <stdio.h>
 
-#if defined HAVE_LIMITS_H || _LIBC
+#if defined HAVE_LIMITS_H || defined _LIBC
 # include <limits.h>
 #endif
 
@@ -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
@@ -582,23 +542,6 @@ static int status_only = 0; /* With -c, don't generate any output.
 static int warn = 0; /* With -w, print a message to standard error warning
                         about each improperly formatted MD5 checksum line */
 
-static const char md5sum_usage[] =
-    "md5sum [OPTION] [FILE]...\n"
-    "or:    md5sum [OPTION] -c [FILE]\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
-    "\nPrint or check MD5 checksums.\n\n"
-    "Options:\n"
-    "With no FILE, or when FILE is -, read standard input.\n\n"
-    "\t-b\tread files in binary mode\n"
-    "\t-c\tcheck MD5 sums against given list\n"
-    "\t-t\tread files in text mode (default)\n"
-    "\t-g\tread a string\n"
-    "\nThe following two options are useful only when verifying checksums:\n"
-    "\t-s,\tdon't output anything, status code shows success\n"
-    "\t-w,\twarn about improperly formated MD5 checksum lines\n"
-#endif
-;
-
 static int split_3(char *s,
                    size_t s_len,
                    unsigned char **u,
@@ -708,13 +651,13 @@ static int md5_file(const char *filename,
   } else {
     fp = fopen(filename, OPENOPTS(binary));
     if (fp == NULL) {
-      errorMsg("md5sum: %s: %s\n", filename, strerror(errno));
+      errorMsg("%s: %s\n", filename, strerror(errno));
       return FALSE;
     }
   }
 
   if (md5_stream(fp, md5_result)) {
-    errorMsg("md5sum: %s: %s\n", filename, strerror(errno));
+    errorMsg("%s: %s\n", filename, strerror(errno));
 
     if (fp != stdin)
       fclose(fp);
@@ -722,7 +665,7 @@ static int md5_file(const char *filename,
   }
 
   if (fp != stdin && fclose(fp) == EOF) {
-    errorMsg("md5sum: %s: %s\n", filename, strerror(errno));
+    errorMsg("%s: %s\n", filename, strerror(errno));
     return FALSE;
   }
 
@@ -746,7 +689,7 @@ static int md5_check(const char *checkfile_name)
   } else {
     checkfile_stream = fopen(checkfile_name, "r");
     if (checkfile_stream == NULL) {
-      errorMsg("md5sum: %s: %s\n", checkfile_name, strerror(errno));
+      errorMsg("%s: %s\n", checkfile_name, strerror(errno));
       return FALSE;
     }
   }
@@ -827,7 +770,7 @@ static int md5_check(const char *checkfile_name)
     free(line);
 
   if (ferror(checkfile_stream)) {
-    errorMsg("%s: read error", checkfile_name); /* */
+    errorMsg("%s: read error\n", checkfile_name); /* */
     return FALSE;
   }
 
@@ -919,22 +862,22 @@ int md5sum_main(int argc,
 
   if (file_type_specified && do_check) {
     errorMsg("the -b and -t options are meaningless when verifying checksums\n");
-    exit FALSE;
+       return EXIT_FAILURE;
   }
 
   if (n_strings > 0 && do_check) {
     errorMsg("the -g and -c options are mutually exclusive\n");
-    exit FALSE;
+       return EXIT_FAILURE;
   }
 
   if (status_only && !do_check) {
     errorMsg("the -s option is meaningful only when verifying checksums\n");
-    exit FALSE;
+       return EXIT_FAILURE;
   }
 
   if (warn && !do_check) {
     errorMsg("the -w option is meaningful only when verifying checksums\n");
-    exit FALSE;
+       return EXIT_FAILURE;
   }
 
   if (n_strings > 0) {
@@ -942,7 +885,7 @@ int md5sum_main(int argc,
 
     if (optind < argc) {
       errorMsg("no files may be specified when using -g\n");
-      exit FALSE;
+         return EXIT_FAILURE;
     }
     for (i = 0; i < n_strings; ++i) {
       size_t cnt;
@@ -1008,14 +951,17 @@ int md5sum_main(int argc,
   }
 
   if (fclose (stdout) == EOF) {
-    errorMsg("write error");
-    exit FALSE;
+    errorMsg("write error\n");
+       return EXIT_FAILURE;
   }
 
   if (have_read_stdin && fclose (stdin) == EOF) {
-    errorMsg("standard input");
-    exit FALSE;
+    errorMsg("standard input\n");
+       return EXIT_FAILURE;
   }
 
-  exit (err == 0 ? TRUE : FALSE);
+  if (err == 0)
+         return EXIT_SUCCESS;
+  else
+         return EXIT_FAILURE;
 }