]> git.ipfire.org Git - people/ms/strongswan.git/commitdiff
byteorder: Provide a fallback for le32toh/htole32()
authorMartin Willi <martin@strongswan.org>
Tue, 10 Nov 2015 07:12:35 +0000 (08:12 +0100)
committerMartin Willi <martin@strongswan.org>
Fri, 4 Dec 2015 09:29:09 +0000 (10:29 +0100)
Some older toolchains don't provide these macros, so implement them using
the gcc builtins. We also provide 64-bit variants as used by chapoly.

src/libstrongswan/utils/utils/byteorder.h

index ef2bddbf71e45e2a765f770bf3d094736750a078..68a7b33636d4c4c67553744fbe0fbb6a17ca131a 100644 (file)
@@ -158,6 +158,26 @@ static inline u_int64_t untoh64(void *network)
 #endif
 }
 
+#ifndef le32toh
+# if BYTE_ORDER == BIG_ENDIAN
+#  define le32toh(x) __builtin_bswap32(x)
+#  define htole32(x) __builtin_bswap32(x)
+# else
+#  define le32toh(x) (x)
+#  define htole32(x) (x)
+# endif
+#endif
+
+#ifndef le64toh
+# if BYTE_ORDER == BIG_ENDIAN
+#  define le64toh(x) __builtin_bswap64(x)
+#  define htole64(x) __builtin_bswap64(x)
+# else
+#  define le64toh(x) (x)
+#  define htole64(x) (x)
+# endif
+#endif
+
 /**
  * Read a 32-bit value in little-endian order from unaligned address.
  *