This allow to define macros based on endianess in public headers Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- spice/macros.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/spice/macros.h b/spice/macros.h index 62157b4..3538989 100644 --- a/spice/macros.h +++ b/spice/macros.h @@ -359,4 +359,59 @@ #endif /* generic */ +/* detect endianess */ +#undef SPICE_ENDIAN +#define SPICE_ENDIAN_LITTLE 4321 +#define SPICE_ENDIAN_BIG 1234 +#define SPICE_ENDIAN_PDP 2143 + +/* gcc already defined these, use them */ +#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \ + && defined(__ORDER_BIG_ENDIAN__) && defined(__ORDER_PDP_ENDIAN__) +# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +# define SPICE_ENDIAN SPICE_ENDIAN_LITTLE +# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +# define SPICE_ENDIAN SPICE_ENDIAN_BIG +# elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__ +# define SPICE_ENDIAN SPICE_ENDIAN_PDP +# else +# error __BYTE_ORDER__ not defined correctly +# endif +#endif + +/* use suggestions at http://sourceforge.net/p/predef/wiki/Endianness/ */ +#ifndef SPICE_ENDIAN +# if defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) \ + || defined(__THUMBEL__) || defined(__AARCH64EL__) \ + || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) +# define SPICE_ENDIAN SPICE_ENDIAN_LITTLE +# endif +# if defined(__BIG_ENDIAN__) || defined(__ARMEB__) \ + || defined(__THUMBEB__) || defined(__AARCH64EB__) \ + || defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) +# ifdef SPICE_ENDIAN +# error Both little and big endian detected +# endif +# define SPICE_ENDIAN SPICE_ENDIAN_BIG +# endif +#endif + +/* MS compiler */ +#if !defined(SPICE_ENDIAN) && defined(_MSC_VER) +/* Windows support only little endian arm */ +# if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) \ + || defined(_M_ARM) +# define SPICE_ENDIAN SPICE_ENDIAN_LITTLE +# endif +#endif + +#if !defined(SPICE_ENDIAN) +#error Unable to detect processor endianess +#endif + +#if SPICE_ENDIAN == SPICE_ENDIAN_PDP +#error PDP endianess not supported by Spice +#endif + + #endif /* _H_SPICE_MACROS */ -- 2.1.0 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/spice-devel