[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: BUILD: Fix bswap portability
From: |
gnunet |
Subject: |
[gnunet] branch master updated: BUILD: Fix bswap portability |
Date: |
Mon, 28 Jun 2021 07:19:41 +0200 |
This is an automated email from the git hooks/post-receive script.
martin-schanzenbach pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 3ae831780 BUILD: Fix bswap portability
3ae831780 is described below
commit 3ae831780b5681764a7d0505fa94f3fdaa43e1d8
Author: Martin Schanzenbach <mschanzenbach@posteo.de>
AuthorDate: Mon Jun 28 07:16:36 2021 +0200
BUILD: Fix bswap portability
---
src/include/gnunet_common.h | 24 ++++++++++++------------
src/include/platform.h | 18 ++++++++++++++++++
2 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 4dab71f7f..7477ca4c8 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -143,36 +143,36 @@ enum GNUNET_GenericReturnValue
*/
#if __BYTE_ORDER == __LITTLE_ENDIAN
-#define GNUNET_htobe16(x) __bswap_16 (x)
+#define GNUNET_htobe16(x) BYTE_SWAP_16 (x)
#define GNUNET_htole16(x) (x)
-#define GNUNET_be16toh(x) __bswap_16 (x)
+#define GNUNET_be16toh(x) BYTE_SWAP_16 (x)
#define GNUNET_le16toh(x) (x)
-#define GNUNET_htobe32(x) __bswap_32 (x)
+#define GNUNET_htobe32(x) BYTE_SWAP_32 (x)
#define GNUNET_htole32(x) (x)
-#define GNUNET_be32toh(x) __bswap_32 (x)
+#define GNUNET_be32toh(x) BYTE_SWAP_32 (x)
#define GNUNET_le32toh(x) (x)
-#define GNUNET_htobe64(x) __bswap_64 (x)
+#define GNUNET_htobe64(x) BYTE_SWAP_64 (x)
#define GNUNET_htole64(x) (x)
-#define GNUNET_be64toh(x) __bswap_64 (x)
+#define GNUNET_be64toh(x) BYTE_SWAP_64 (x)
#define GNUNET_le64toh(x) (x)
#endif
#if __BYTE_ORDER == __BIG_ENDIAN
#define GNUNET_htobe16(x) (x)
-#define GNUNET_htole16(x) __bswap_16 (x)
+#define GNUNET_htole16(x) BYTE_SWAP_16 (x)
#define GNUNET_be16toh(x) (x)
-#define GNUNET_le16toh(x) __bswap_16 (x)
+#define GNUNET_le16toh(x) BYTE_SWAP_16 (x)
#define GNUNET_htobe32(x) (x)
-#define GNUNET_htole32(x) __bswap_32 (x)
+#define GNUNET_htole32(x) BYTE_SWAP_32 (x)
#define GNUNET_be32toh(x) (x)
-#define GNUNET_le32toh(x) __bswap_32 (x)
+#define GNUNET_le32toh(x) BYTE_SWAP_32 (x)
#define GNUNET_htobe64(x) (x)
-#define GNUNET_htole64(x) __bswap_64 (x)
+#define GNUNET_htole64(x) BYTE_SWAP_64 (x)
#define GNUNET_be64toh(x) (x)
-#define GNUNET_le64toh(x) __bswap_64 (x)
+#define GNUNET_le64toh(x) BYTE_SWAP_64 (x)
#endif
diff --git a/src/include/platform.h b/src/include/platform.h
index 32bb637f1..da70893a7 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -199,6 +199,24 @@
#undef HAVE_MREMAP
#endif
+#if defined(__linux__)
+#define BYTE_SWAP_16(x) __bswap_16 (x)
+#define BYTE_SWAP_32(x) __bswap_32 (x)
+#define BYTE_SWAP_64(x) __bswap_64 (x)
+#else
+#define BYTE_SWAP_16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
+
+#define BYTE_SWAP_32(x) \
+ ((((x) & 0x000000ffU) << 24) | (((x) & 0x0000ff00U) << 8) \
+ | (((x) & 0x00ff0000U) >> 8) | (((x) & 0xff000000U) >> 24))
+
+#define BYTE_SWAP_64(x) \
+ ((((x) & 0x00000000000000ffUL) << 56) | (((x) & 0x000000000000ff00UL) << 40)
\
+ | (((x) & 0x0000000000ff0000UL) << 24) | (((x) & 0x00000000ff000000UL) <<
8) \
+ | (((x) & 0x000000ff00000000UL) >> 8) | (((x) & 0x0000ff0000000000UL) >>
24) \
+ | (((x) & 0x00ff000000000000UL) >> 40) | (((x) & 0xff00000000000000UL) >> \
+ 56))
+#endif
#if ! HAVE_ATOLL
long long
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: BUILD: Fix bswap portability,
gnunet <=