From: Jesper Derehag Date: Wed, 23 Apr 2014 15:45:26 +0000 (+0200) Subject: Add fallback for betoh/htobe if they do not exist X-Git-Tag: v2.0.0-pre1~1550 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=62f11f7472d3cb862770d7121c5cab23424cd16a Add fallback for betoh/htobe if they do not exist For older systems endian.h may not contain the betoh/htobe macros. If they are missing, add them and make sure that any user of htobe/betoh uses the compat/endian.h Signed-off-by: Jesper Derehag Tested-by: Jesper Derehag Signed-off-by: Mathieu Desnoyers --- diff --git a/formats/lttng-live/lttng-live-comm.c b/formats/lttng-live/lttng-live-comm.c index 9feb7185..3aad9810 100644 --- a/formats/lttng-live/lttng-live-comm.c +++ b/formats/lttng-live/lttng-live-comm.c @@ -50,6 +50,7 @@ #include #include +#include #include #include "lttng-live.h" diff --git a/include/babeltrace/endian.h b/include/babeltrace/endian.h index f15a44fb..001a4717 100644 --- a/include/babeltrace/endian.h +++ b/include/babeltrace/endian.h @@ -47,7 +47,98 @@ #define BYTE_ORDER __BYTE_ORDER #else #include -#endif + +/* + * htobe/betoh are not defined for glibc < 2.9, so add them explicitly + * if they are missing. + */ +# ifdef __USE_BSD +/* Conversion interfaces. */ +# include + +# if __BYTE_ORDER == __LITTLE_ENDIAN +# ifndef htobe16 +# define htobe16(x) __bswap_16(x) +# endif +# ifndef htole16 +# define htole16(x) (x) +# endif +# ifndef be16toh +# define be16toh(x) __bswap_16(x) +# endif +# ifndef le16toh +# define le16toh(x) (x) +# endif + +# ifndef htobe32 +# define htobe32(x) __bswap_32(x) +# endif +# ifndef htole32 +# define htole32(x) (x) +# endif +# ifndef be32toh +# define be32toh(x) __bswap_32(x) +# endif +# ifndef le32toh +# define le32toh(x) (x) +# endif + +# ifndef htobe64 +# define htobe64(x) __bswap_64(x) +# endif +# ifndef htole64 +# define htole64(x) (x) +# endif +# ifndef be64toh +# define be64toh(x) __bswap_64(x) +# endif +# ifndef le64toh +# define le64toh(x) (x) +# endif + +# else /* __BYTE_ORDER == __LITTLE_ENDIAN */ +# ifndef htobe16 +# define htobe16(x) (x) +# endif +# ifndef htole16 +# define htole16(x) __bswap_16(x) +# endif +# ifndef be16toh +# define be16toh(x) (x) +# endif +# ifndef le16toh +# define le16toh(x) __bswap_16(x) +# endif + +# ifndef htobe32 +# define htobe32(x) (x) +# endif +# ifndef htole32 +# define htole32(x) __bswap_32(x) +# endif +# ifndef be32toh +# define be32toh(x) (x) +# endif +# ifndef le32toh +# define le32toh(x) __bswap_32(x) +# endif + +# ifndef htobe64 +# define htobe64(x) (x) +# endif +# ifndef htole64 +# define htole64(x) __bswap_64(x) +# endif +# ifndef be64toh +# define be64toh(x) (x) +# endif +# ifndef le64toh +# define le64toh(x) __bswap_64(x) +# endif + +# endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ +# endif /* __USE_BSD */ +#endif /* else -- __FreeBSD__ */ #ifndef FLOAT_WORD_ORDER #ifdef __FLOAT_WORD_ORDER