diff options
Diffstat (limited to 'compat/bswap.h')
-rw-r--r-- | compat/bswap.h | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/compat/bswap.h b/compat/bswap.h index 5cc4acbfcc..5061214f73 100644 --- a/compat/bswap.h +++ b/compat/bswap.h @@ -17,16 +17,30 @@ static inline uint32_t default_swab32(uint32_t val) ((val & 0x000000ff) << 24)); } +#undef bswap32 + #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) -#define bswap32(x) ({ \ - uint32_t __res; \ - if (__builtin_constant_p(x)) { \ - __res = default_swab32(x); \ - } else { \ - __asm__("bswap %0" : "=r" (__res) : "0" (x)); \ - } \ - __res; }) +#define bswap32 git_bswap32 +static inline uint32_t git_bswap32(uint32_t x) +{ + uint32_t result; + if (__builtin_constant_p(x)) + result = default_swab32(x); + else + __asm__("bswap %0" : "=r" (result) : "0" (x)); + return result; +} + +#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) + +#include <stdlib.h> + +#define bswap32(x) _byteswap_ulong(x) + +#endif + +#ifdef bswap32 #undef ntohl #undef htonl |