From 53d467abf898aa7dba20cb0f0b6f1b86000731de Mon Sep 17 00:00:00 2001 From: jsteube Date: Sat, 21 Jan 2017 18:03:47 +0100 Subject: [PATCH] Fix travis-ci error caused by __builtin_bswapXX() --- include/bitops.h | 1 + src/bitops.c | 12 ++++++++++++ src/interface.c | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/bitops.h b/include/bitops.h index 0b9d1030f..30b53c30b 100644 --- a/include/bitops.h +++ b/include/bitops.h @@ -11,6 +11,7 @@ u32 rotr32 (const u32 a, const u32 n); u64 rotl64 (const u64 a, const u64 n); u64 rotr64 (const u64 a, const u64 n); +u16 byte_swap_16 (const u16 n); u32 byte_swap_32 (const u32 n); u64 byte_swap_64 (const u64 n); diff --git a/src/bitops.c b/src/bitops.c index 5cee34fa9..d40904731 100644 --- a/src/bitops.c +++ b/src/bitops.c @@ -43,6 +43,18 @@ u64 rotr64 (const u64 a, const u64 n) #endif } +u16 byte_swap_16 (const u16 n) +{ + #if defined (_MSC_VER) + return _byteswap_ushort (n); + #elif defined (__clang__) || defined (__GNUC__) + return __builtin_bswap16 (n); + #else + return (n & 0xff00) >> 8 + | (n & 0x00ff) << 8; + #endif +} + u32 byte_swap_32 (const u32 n) { #if defined (_MSC_VER) diff --git a/src/interface.c b/src/interface.c index 3bc4f4a9d..a95d13de0 100644 --- a/src/interface.c +++ b/src/interface.c @@ -13168,8 +13168,8 @@ int luks_parse_hash (u8 *input_buf, u32 input_len, hash_t *hash_buf, MAYBE_UNUSE // verify the content - #define ntohs __builtin_bswap16 - #define ntohl __builtin_bswap32 + #define ntohs byte_swap_16 + #define ntohl byte_swap_32 char luks_magic[6] = LUKS_MAGIC;