Add fallback for betoh/htobe if they do not exist
authorJesper Derehag <jderehag@hotmail.com>
Wed, 23 Apr 2014 15:45:26 +0000 (17:45 +0200)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 26 Apr 2014 10:20:59 +0000 (12:20 +0200)
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 <jderehag@hotmail.com>
Tested-by: Jesper Derehag <jderehag@hotmail.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/lttng-live/lttng-live-comm.c
include/babeltrace/endian.h

index 9feb7185c76d0d1cdea4c1e5dfd79dc300849dbc..3aad981008bbe02022ecce743fb7de2e9c6ee2c9 100644 (file)
@@ -50,6 +50,7 @@
 #include <babeltrace/ctf/events-internal.h>
 #include <formats/ctf/events-private.h>
 
+#include <babeltrace/endian.h>
 #include <babeltrace/compat/memstream.h>
 
 #include "lttng-live.h"
index f15a44fb857b1370a54ffa36ec754a0c5a4ee065..001a47172b9c51a954758bcee36af4f3b79d8a56 100644 (file)
 #define BYTE_ORDER     __BYTE_ORDER
 #else
 #include <endian.h>
-#endif
+
+/*
+ * htobe/betoh are not defined for glibc < 2.9, so add them explicitly
+ * if they are missing.
+ */
+# ifdef __USE_BSD
+/* Conversion interfaces. */
+#  include <byteswap.h>
+
+#  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
This page took 0.026598 seconds and 4 git commands to generate.