diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-07-15 21:22:19 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-07-16 13:47:36 -0700 |
commit | c999af595f4a8f7d30b6d7c822e2a1caf3298389 (patch) | |
tree | 27c22a95ff9342bbdc1e94fb4806279f61f058af /src/ints | |
parent | 17605f7782ac9a73a3dacf6ce27e5dae36160f01 (diff) | |
download | tmwa-c999af595f4a8f7d30b6d7c822e2a1caf3298389.tar.gz tmwa-c999af595f4a8f7d30b6d7c822e2a1caf3298389.tar.bz2 tmwa-c999af595f4a8f7d30b6d7c822e2a1caf3298389.tar.xz tmwa-c999af595f4a8f7d30b6d7c822e2a1caf3298389.zip |
Revert bounds checks and go back to signed integers
Diffstat (limited to 'src/ints')
-rw-r--r-- | src/ints/little.hpp | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/ints/little.hpp b/src/ints/little.hpp index 0dbbb61..b3046f7 100644 --- a/src/ints/little.hpp +++ b/src/ints/little.hpp @@ -64,6 +64,7 @@ namespace ints uint8_t data[8]; }; + inline __attribute__((warn_unused_result)) bool native_to_network(Byte *net, uint8_t nat) { @@ -131,6 +132,75 @@ namespace ints *nat = tmp; return true; } + + + inline __attribute__((warn_unused_result)) + bool native_to_network(Byte *net, int8_t nat) + { + net->value = nat; + return true; + } + inline __attribute__((warn_unused_result)) + bool native_to_network(Little16 *net, int16_t nat) + { + if (__BYTE_ORDER == __BIG_ENDIAN) + nat = bswap16(nat); + __builtin_memcpy(net, &nat, 2); + return true; + } + inline __attribute__((warn_unused_result)) + bool native_to_network(Little32 *net, int32_t nat) + { + if (__BYTE_ORDER == __BIG_ENDIAN) + nat = __builtin_bswap32(nat); + __builtin_memcpy(net, &nat, 4); + return true; + } + inline __attribute__((warn_unused_result)) + bool native_to_network(Little64 *net, int64_t nat) + { + if (__BYTE_ORDER == __BIG_ENDIAN) + nat = __builtin_bswap64(nat); + __builtin_memcpy(net, &nat, 8); + return true; + } + + inline __attribute__((warn_unused_result)) + bool network_to_native(int8_t *nat, Byte net) + { + *nat = net.value; + return true; + } + inline __attribute__((warn_unused_result)) + bool network_to_native(int16_t *nat, Little16 net) + { + int16_t tmp; + __builtin_memcpy(&tmp, &net, 2); + if (__BYTE_ORDER == __BIG_ENDIAN) + tmp = bswap16(tmp); + *nat = tmp; + return true; + } + inline __attribute__((warn_unused_result)) + bool network_to_native(int32_t *nat, Little32 net) + { + int32_t tmp; + __builtin_memcpy(&tmp, &net, 4); + if (__BYTE_ORDER == __BIG_ENDIAN) + tmp = __builtin_bswap32(tmp); + *nat = tmp; + return true; + } + inline __attribute__((warn_unused_result)) + bool network_to_native(int64_t *nat, Little64 net) + { + int64_t tmp; + __builtin_memcpy(&tmp, &net, 8); + if (__BYTE_ORDER == __BIG_ENDIAN) + tmp = __builtin_bswap64(tmp); + *nat = tmp; + return true; + } } // namespace ints using ints::Byte; |