summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--md5.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/md5.c b/md5.c
index da3692b..d7934c2 100644
--- a/md5.c
+++ b/md5.c
@@ -42,15 +42,28 @@
#include <string.h>
#include "md5.h"
-#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-# define HIGHFIRST
-#elif defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
-# define HIGHFIRST
-#elif defined(__sparc) || defined(__mips)
-# define HIGHFIRST
+/*
+ * Try and determine endianness of the target system.
+ *
+ * Other projects seem to use endian.h and variants, but these are
+ * in non standard locations, and may mess up cross compiling.
+ *
+ * Here at least the endianess can be set explicitly with
+ * -DLITTLE_ENDIAN or -DBIG_ENDIAN.
+ */
+#if !defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)
+# if defined(__LITTLE_ENDIAN__) || \
+ (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
+# define LITTLE_ENDIAN 1
+# elif defined(__BIG_ENDIAN__) || \
+ (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
+# define BIG_ENDIAN 1
+# else
+# error Failed determining endianness of system
+# endif
#endif
-#ifndef HIGHFIRST
+#ifdef LITTLE_ENDIAN
# define byteReverse(buf, len) /* Nothing */
#else
void byteReverse(unsigned char *buf, unsigned longs);