summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>2014-03-02 21:51:39 +0000
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>2014-03-02 21:51:39 +0000
commit8a5052072cdeec3ca23350befbc0903001bea52c (patch)
tree9715c022b85063d923cc324ac3eb4345e386c623
parent5d827a1f40373f41d2bce6b59719b930bcd646bd (diff)
downloadlibpam-radius-auth-8a5052072cdeec3ca23350befbc0903001bea52c.tar.gz
libpam-radius-auth-8a5052072cdeec3ca23350befbc0903001bea52c.zip
Use a combination of endian macros
-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);