1
0
forked from 0ad/0ad
0ad/source/lib/byte_order.cpp
prefect 04650efe7a Lots of gcc -Wall fixes. The common ones:
- switch() statements don't handle all values in an enum
- missing \n at end of file
- non-virtual destructors in classes containing virtual functions
- order of initializers in constructor initializer lists
... some other stuff (signedness, nested comments, unused variables) as
well.

This was SVN commit r2864.
2005-10-07 15:24:29 +00:00

68 lines
1009 B
C++

#include "precompiled.h"
#include "byte_order.h"
#include "sdl.h"
u16 read_le16(const void* p)
{
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
const u8* _p = (const u8*)p;
return (u16)_p[0] | (u16)_p[1] << 8;
#else
return *(u16*)p;
#endif
}
u32 read_le32(const void* p)
{
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
return SDL_Swap32(*(u32*)p);
#else
return *(u32*)p;
#endif
}
u64 read_le64(const void* p)
{
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
return SDL_Swap64(*(u64*)p);
#else
return *(u64*)p;
#endif
}
u16 read_be16(const void* p)
{
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
return *(u16*)p;
#else
const u8* _p = (const u8*)p;
return (u16)_p[0] | (u16)_p[1] << 8;
#endif
}
u32 read_be32(const void* p)
{
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
return *(u32*)p;
#else
return SDL_Swap32(*(u32*)p);
#endif
}
u64 read_be64(const void* p)
{
#if SDL_BYTE_ORDER == SDL_BIG_ENDIAN
return *(u64*)p;
#else
return SDL_Swap64(*(u64*)p);
#endif
}