forked from 0ad/0ad
janwas
85a8d217de
byte_order: use config.h defines (avoids pulling in sdl.h everywhere) precompiled: now include *all* C++ headers This was SVN commit r2436.
47 lines
721 B
C++
47 lines
721 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
|
|
}
|
|
|
|
|
|
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
|
|
}
|