diff options
author | Dan Shumow <shumow@gmail.com> | 2017-07-01 22:36:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-01 22:36:15 +0300 |
commit | 19d97bf5af05312267c2e874ee6bcf584d9e9681 (patch) | |
tree | b2e6dd60cec50a2acc3330323fe06cc0c2eeca7e | |
parent | 3f14d1bbe2724610f25befff15c4899903182428 (diff) | |
parent | c93f0b4401de582685f9237a832fa6b3716cfe2a (diff) |
Merge pull request #37 from avar/fixup-pull-request-34
Fix endian detection logic for Sparc, little endian BSD etc.
-rw-r--r-- | lib/sha1.c | 39 |
1 files changed, 24 insertions, 15 deletions
@@ -10,6 +10,9 @@ #include <memory.h> #include <stdio.h> #include <stdlib.h> +#ifdef __unix__ +#include <sys/types.h> /* make sure macros like _BIG_ENDIAN visible */ +#endif #endif #ifdef SHA1DC_CUSTOM_INCLUDE_SHA1_C @@ -54,9 +57,8 @@ #define SHA1DC_BIGENDIAN #endif -#else /* Not under GCC-alike */ - -#if defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) +/* Not under GCC-alike */ +#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) /* * Should detect Big Endian under glibc.git since 14245eb70e ("entered * into RCS", 1992-11-25). Defined in <endian.h> which will have been @@ -67,11 +69,22 @@ #define SHA1DC_BIGENDIAN #endif -#else /* Not under GCC-alike or glibc */ +/* Not under GCC-alike or glibc */ +#elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) +/* + * *BSD and newlib (embeded linux, cygwin, etc). + * the defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) part prevents + * this condition from matching with Solaris/sparc. + * (Solaris defines only one endian macro) + */ +#if _BYTE_ORDER == _BIG_ENDIAN +#define SHA1DC_BIGENDIAN +#endif -#if (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ - defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \ - defined(__sparc)) +/* Not under GCC-alike or glibc or *BSD or newlib */ +#elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \ + defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \ + defined(__sparc)) /* * Should define Big Endian for a whitelist of known processors. See * https://sourceforge.net/p/predef/wiki/Endianness/ and @@ -79,23 +92,19 @@ */ #define SHA1DC_BIGENDIAN -#else /* Not under GCC-alike or glibc or <processor whitelist> */ - -#if defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) +/* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> */ +#elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR) /* * As a last resort before we do anything else we're not 100% sure * about below, we blacklist specific processors here. We could add * more, see e.g. https://wiki.debian.org/ArchitectureSpecificsMemo */ -#else /* Not under GCC-alike or glibc or <processor whitelist> or <processor blacklist> */ +#else /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> or <processor blacklist> */ /* We do nothing more here for now */ /*#error "Uncomment this to see if you fall through all the detection"*/ -#endif /* !SHA1DC_ON_INTEL_LIKE_PROCESSOR */ -#endif /* Big Endian under whitelist of processors */ -#endif /* Big Endian under glibc */ -#endif /* Big Endian under GCC-alike */ +#endif /* Big Endian detection */ #if (defined(SHA1DC_FORCE_LITTLEENDIAN) && defined(SHA1DC_BIGENDIAN)) #undef SHA1DC_BIGENDIAN |