summaryrefslogtreecommitdiffstats
path: root/src/Endianness.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Endianness.h')
-rw-r--r--src/Endianness.h31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/Endianness.h b/src/Endianness.h
index 86eb369f5..6a2593077 100644
--- a/src/Endianness.h
+++ b/src/Endianness.h
@@ -1,12 +1,14 @@
#pragma once
+#define ntohll(x) ((((UInt64)ntohl((u_long)x)) << 32) + ntohl(x >> 32))
+
// Changes endianness
-inline unsigned long long HostToNetwork8(const void* a_Value )
+inline UInt64 HostToNetwork8(const void * a_Value)
{
unsigned long long __HostToNetwork8;
memcpy( &__HostToNetwork8, a_Value, sizeof( __HostToNetwork8 ) );
@@ -18,7 +20,7 @@ inline unsigned long long HostToNetwork8(const void* a_Value )
-inline unsigned int HostToNetwork4(const void* a_Value )
+inline UInt32 HostToNetwork4(const void* a_Value )
{
unsigned int __HostToNetwork4;
memcpy( &__HostToNetwork4, a_Value, sizeof( __HostToNetwork4 ) );
@@ -30,11 +32,10 @@ inline unsigned int HostToNetwork4(const void* a_Value )
-inline double NetworkToHostDouble8(const void* a_Value )
+inline double NetworkToHostDouble8(const void * a_Value)
{
-#define ntohll(x) ((((unsigned long long)ntohl((u_long)x)) << 32) + ntohl(x >> 32))
- unsigned long long buf = 0;//(*(unsigned long long*)a_Value);
- memcpy( &buf, a_Value, 8 );
+ UInt64 buf = 0;
+ memcpy(&buf, a_Value, 8);
buf = ntohll(buf);
double x;
memcpy(&x, &buf, sizeof(double));
@@ -45,23 +46,25 @@ inline double NetworkToHostDouble8(const void* a_Value )
-inline long long NetworkToHostLong8(const void * a_Value )
+inline Int64 NetworkToHostLong8(const void * a_Value)
{
- unsigned long long buf = *(unsigned long long*)a_Value;
+ UInt64 buf;
+ memcpy(&buf, &a_Value, 8);
buf = ntohll(buf);
- return *reinterpret_cast<long long *>(&buf);
+ return *reinterpret_cast<Int64 *>(&buf);
}
-inline float NetworkToHostFloat4(const void* a_Value )
+inline float NetworkToHostFloat4(const void * a_Value)
{
- u_long buf = *(u_long*)a_Value;
- buf = ntohl( buf );
- float x = 0;
- memcpy( &x, &buf, sizeof(float) );
+ UInt32 buf;
+ float x;
+ memcpy(&buf, &a_Value, 4);
+ buf = ntohl(buf);
+ memcpy(&x, &buf, sizeof(float));
return x;
}