Commit 242e5b84 authored by Jason Hiser's avatar Jason Hiser 🚜

Merge branch 'fixes-for-windows' into 'master'

Windows missing big-endian/little-endian conversion routines (e.g. be16toh)

See merge request !11
parents ddb106c4 953f45ba
Pipeline #9355 failed with stages
in 1 minute and 54 seconds
......@@ -20,6 +20,46 @@
// @HEADER_END
#ifdef _WIN32
# include <windows.h>
# undef max
# undef min
# if defined(_MSC_VER)
# define htobe16(x) _byteswap_ushort(x)
# define htole16(x) (x)
# define be16toh(x) _byteswap_ushort(x)
# define le16toh(x) (x)
# define htobe32(x) _byteswap_ulong(x)
# define htole32(x) (x)
# define be32toh(x) _byteswap_ulong(x)
# define le32toh(x) (x)
# define htobe64(x) _byteswap_uint64(x)
# define htole64(x) (x)
# define be64toh(x) _byteswap_uint64(x)
# define le64toh(x) (x)
# elif defined(__GNUC__) || defined(__clang__)
# define htobe16(x) __builtin_bswap16(x)
# define htole16(x) (x)
# define be16toh(x) __builtin_bswap16(x)
# define le16toh(x) (x)
# define htobe32(x) __builtin_bswap32(x)
# define htole32(x) (x)
# define be32toh(x) __builtin_bswap32(x)
# define le32toh(x) (x)
# define htobe64(x) __builtin_bswap64(x)
# define htole64(x) (x)
# define be64toh(x) __builtin_bswap64(x)
# define le64toh(x) (x)
# endif // _MSC_VER
#endif // _WIN32
#include <iostream>
#include <iomanip>
#include <fstream>
......@@ -65,33 +105,36 @@ bool eh_frame_util_t<ptrsize>::read_type(T &value, uint64_t &position, const uin
// set output parameters
position+=sizeof(T);
value=*ptr;
switch(sizeof(T))
switch (sizeof(T))
{
case 1:
break;
case 2:
if(is_be)
value=be16toh(value);
else
value=le16toh(value);
{
const auto in = static_cast<uint16_t>(value);
const auto out = is_be ? be16toh(in) : le16toh(in);
value = static_cast<T>(out);
break;
}
case 4:
if(is_be)
value=be32toh(value);
else
value=le32toh(value);
{
const auto in = static_cast<uint32_t>(value);
const auto out = is_be ? be32toh(in) : le32toh(in);
value = static_cast<T>(out);
break;
}
case 8:
if(is_be)
value=be64toh(value);
else
value=le64toh(value);
{
const auto in = static_cast<uint64_t>(value);
const auto out = is_be ? be64toh(in) : le64toh(in);
value = static_cast<T>(out);
break;
}
default:
throw invalid_argument("Unknown integer size");
}
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment