Some more patchelttes from Larry Doolittle.
[oweals/busybox.git] / md5sum.c
index e4f52075d4974daac86f764d6d32cc2570c0d22c..e5a2abe78ca19973754c243679fe2f3e1d97dc7f 100644 (file)
--- a/md5sum.c
+++ b/md5sum.c
@@ -181,7 +181,14 @@ extern void *md5_buffer __P ((const char *buffer, size_t len, void *resblock));
 //--------end of md5.h
 //----------------------------------------------------------------------------
 
-#define SWAP(n) (n)
+/* Handle endian-ness */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+       #define SWAP(n) (n)
+#else
+       #define SWAP(n) ((n << 24) | ((n&65280)<<8) | ((n&16711680)>>8) | (n>>24))
+#endif
+
+
 
 /* This array contains the bytes used to pad the buffer to the next
    64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
@@ -237,7 +244,7 @@ void *md5_finish_ctx(struct md5_ctx *ctx, void *resbuf)
   /* Put the 64-bit file length in *bits* at the end of the buffer.  */
   *(md5_uint32 *) & ctx->buffer[bytes + pad] = SWAP(ctx->total[0] << 3);
   *(md5_uint32 *) & ctx->buffer[bytes + pad + 4] =
-    SWAP((ctx->total[1] << 3) | (ctx->total[0] >> 29));
+    SWAP( ((ctx->total[1] << 3) | (ctx->total[0] >> 29)) );
 
   /* Process last bytes.  */
   md5_process_block(ctx->buffer, bytes + pad + 8, ctx);
@@ -819,8 +826,6 @@ int md5sum_main(int argc,
        if (string == NULL)
          string = (char **) xmalloc ((argc - 1) * sizeof (char *));
 
-       if (optarg == NULL)
-         optarg = "";
        string[n_strings++] = optarg;
        break;
      }