diff options
author | Beat Bolli <bbolli@ewanet.ch> | 2013-11-08 23:43:33 +0100 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2013-11-10 00:52:17 -0500 |
commit | 170c15b35650427daa47fd8f70676daa1736343f (patch) | |
tree | 709c86f83a027820bf20e7cc83bce520f9591407 /driver_rtcm2.c | |
parent | 79c9ef1c9a5455342300d24333b982cadd58815e (diff) | |
download | gpsd-170c15b35650427daa47fd8f70676daa1736343f.tar.gz |
RTCM V2: use scons to determine the location of <endian.h>.
There are three cases to consider:
- The compiler has built-in endianness macros. In this case, endian.h is
not needed at all. The predefined symols are called
__ORDER_BIG_ENDIAN_, __ORDER_LITTLE_ENDIAN__ and __BYTE_ORDER__.
- <endian.h> exists.
- <sys/endian.h> exists.
This commit covers all three cases at configure time, as Greg Troxel
wanted it.
Relevant discussion can be found on the GCC mailing list:
http://gcc.gnu.org/ml/gcc-help/2007-07/msg00342.html
Of course, the optimal solution would get rid of the bit field
structures and use bits.h to extract the values from the buffer in an
endianess-independent way.
Signed-off-by: Beat Bolli <bbolli@ewanet.ch>
Signed-off-by: Eric S. Raymond <esr@thyrsus.com>
Diffstat (limited to 'driver_rtcm2.c')
-rw-r--r-- | driver_rtcm2.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/driver_rtcm2.c b/driver_rtcm2.c index 91a66861..c3ab6a73 100644 --- a/driver_rtcm2.c +++ b/driver_rtcm2.c @@ -62,32 +62,38 @@ BSD terms apply: see the file COPYING in the distribution root for details. #include "gpsd.h" /* - __BIG_ENDIAN__ and __LITTLE_ENDIAN__ are define in some gcc versions - only, probably depending on the architecture. Try to use endian.h if - the gcc way fails - endian.h also doesn not seem to be available on all - platforms. + __BYTE_ORDER__, __ORDER_BIG_ENDIAN__ and __ORDER_LITTLE_ENDIAN__ are + defined in some gcc versions only, probably depending on the + architecture. Try to use endian.h if the gcc way fails - endian.h also + does not seem to be available on all platforms. */ -#ifdef __BIG_ENDIAN__ + +#if HAVE_BUILTIN_ENDIANNESS +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define WORDS_BIGENDIAN 1 -#else /* __BIG_ENDIAN__ */ -#ifdef __LITTLE_ENDIAN__ +#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #undef WORDS_BIGENDIAN #else -#ifdef __linux__ +#error Unknown endianness! +#endif + +#else /* HAVE_BUILTIN_ENDIANNESS */ + +#if defined(HAVE_ENDIAN_H) #include <endian.h> -#else -/* usual BSD location */ +#elif defined(HAVE_SYS_ENDIAN_H) #include <sys/endian.h> #endif + #if __BYTE_ORDER == __BIG_ENDIAN #define WORDS_BIGENDIAN 1 #elif __BYTE_ORDER == __LITTLE_ENDIAN #undef WORDS_BIGENDIAN #else -#error "unable to determine endianess!" +#error Unknown endianness! #endif /* __BYTE_ORDER */ -#endif /* __LITTLE_ENDIAN__ */ -#endif /* __BIG_ENDIAN__ */ + +#endif /* HAVE_BUILTIN_ENDIANNESS */ /* * Structures for interpreting words in an RTCM-104 2.x message (after |