diff --git a/src/byteswap.hpp b/src/byteswap.hpp new file mode 100644 index 0000000..1a0e534 --- /dev/null +++ b/src/byteswap.hpp @@ -0,0 +1,11 @@ +#pragma once + +#ifdef _MSC_VER +# include +# define bswap_64(x) _byteswap_uint64(x) +#elif defined(__APPLE__) +# include +# define bswap_64(x) OSSwapInt64(x) +#else +# include +#endif diff --git a/src/crypto/bigint.cpp b/src/crypto/bigint.cpp index b76ba92..5bc96d4 100644 --- a/src/crypto/bigint.cpp +++ b/src/crypto/bigint.cpp @@ -5,16 +5,7 @@ #include #include - -#ifdef _MSC_VER -# include -# define bswap_64(x) _byteswap_uint64(x) -#elif defined(__APPLE__) -# include -# define bswap_64(x) OSSwapInt64(x) -#else -# include -#endif +#include "../byteswap.hpp" namespace fc { bigint::bigint( const char* bige, uint32_t l ) { diff --git a/src/uint128.cpp b/src/uint128.cpp index 2912644..c989d3f 100644 --- a/src/uint128.cpp +++ b/src/uint128.cpp @@ -2,11 +2,7 @@ #include #include #include -#ifdef WIN32 -#include -#else -#include -#endif +#include "byteswap.hpp" namespace fc { @@ -118,10 +114,9 @@ namespace fc } - #define bswap64(y) (((uint64_t)ntohl(y)) << 32 | ntohl(y>>32)) uint128::operator bigint()const { - auto tmp = uint128( bswap64( hi ), bswap64( lo ) ); + auto tmp = uint128( bswap_64( hi ), bswap_64( lo ) ); bigint bi( (char*)&tmp, sizeof(tmp) ); return bi; }