From 3e146f1cf64b48b4deee5793f67dac98ea077900 Mon Sep 17 00:00:00 2001 From: Roman Yeryomin Date: Tue, 4 Mar 2014 00:32:10 +0200 Subject: Fix endianess Signed-off-by: Roman Yeryomin --- rtkmib.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/rtkmib.c b/rtkmib.c index bfdf8b0..13870f1 100644 --- a/rtkmib.c +++ b/rtkmib.c @@ -62,17 +62,28 @@ static int flash_read( char *mtd, int offset, int len, char *buf ) return err; } +int is_big_endian( void ) +{ + union { + uint32_t i; + char c[4]; + } e = { 0x01000000 }; + + return e.c[0]; +} + inline uint16_t swap16( uint16_t x ) { - return ((x >> 8) & 0xff) | (x << 8); + return is_big_endian()? x : ((x >> 8) & 0xff) | (x << 8); } inline uint32_t swap32( uint32_t x ) { - return (x >> 24) | - ((x << 8) & 0x00ff0000) | - ((x >> 8) & 0x0000ff00) | - (x << 24); + return is_big_endian()? x : + (x >> 24) | + ((x << 8) & 0x00ff0000) | + ((x >> 8) & 0x0000ff00) | + (x << 24); } #define RING_SIZE 4096 /* size of ring buffer, must be power of 2 */ -- cgit v1.2.3