summaryrefslogtreecommitdiff
path: root/util/cbfstool/swab.h
diff options
context:
space:
mode:
Diffstat (limited to 'util/cbfstool/swab.h')
-rw-r--r--util/cbfstool/swab.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/cbfstool/swab.h b/util/cbfstool/swab.h
index c5e43709a6..22ae8b41b8 100644
--- a/util/cbfstool/swab.h
+++ b/util/cbfstool/swab.h
@@ -15,6 +15,15 @@
*
*/
+#if !defined(__APPLE__) && !defined(__NetBSD__)
+#define ntohl(x) (is_big_endian() ? (uint32_t)(x) : swab32(x))
+#define htonl(x) (is_big_endian() ? (uint32_t)(x) : swab32(x))
+#elif defined(__NetBSD__)
+#include <arpa/inet.h>
+#endif
+#define ntohll(x) (is_big_endian() ? (uint64_t)(x) : swab64(x))
+#define htonll(x) (is_big_endian() ? (uint64_t)(x) : swab64(x))
+
/* casts are necessary for constants, because we never know how for sure
* how U/UL/ULL map to __u16, __u32, __u64. At least not in a portable way.
*/
@@ -41,4 +50,7 @@
(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) ))
+/* common.c */
+int is_big_endian(void);
+
#endif /* _SWAB_H */