mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-protocol
synced 2025-12-29 00:41:31 +00:00
Detects processor endianess using preprocessor
This allow to define macros based on endianess in public headers Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
03a28f5856
commit
3ab16f2dad
@ -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 */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user