summaryrefslogtreecommitdiffstats
path: root/src/Endianness.h
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-04-04 10:13:25 +0200
committermadmaxoft <github@xoft.cz>2014-04-04 10:13:25 +0200
commit8825d30aabbee8cb2e452dc5a17deb6f9b6892a7 (patch)
tree1f06f2d45652458c0490b794eae6a9e17596c85e /src/Endianness.h
parentFixed Clang warnings in itemhandlers. (diff)
downloadcuberite-8825d30aabbee8cb2e452dc5a17deb6f9b6892a7.tar
cuberite-8825d30aabbee8cb2e452dc5a17deb6f9b6892a7.tar.gz
cuberite-8825d30aabbee8cb2e452dc5a17deb6f9b6892a7.tar.bz2
cuberite-8825d30aabbee8cb2e452dc5a17deb6f9b6892a7.tar.lz
cuberite-8825d30aabbee8cb2e452dc5a17deb6f9b6892a7.tar.xz
cuberite-8825d30aabbee8cb2e452dc5a17deb6f9b6892a7.tar.zst
cuberite-8825d30aabbee8cb2e452dc5a17deb6f9b6892a7.zip
Diffstat (limited to '')
-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;
}