From 8a5052072cdeec3ca23350befbc0903001bea52c Mon Sep 17 00:00:00 2001 From: Arran Cudbard-Bell Date: Sun, 2 Mar 2014 21:51:39 +0000 Subject: Use a combination of endian macros --- md5.c | 27 ++++++++++++++++++++------- 1 file 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 #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); -- cgit v1.2.3