Allow tools to work properly on big endian systems
This commit is contained in:
parent
c69c75bf9b
commit
504b225b62
|
@ -19,10 +19,17 @@ typedef unsigned int u32;
|
|||
typedef unsigned long long u64;
|
||||
typedef float f32;
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define bswap16(x) x
|
||||
#define bswap32(x) x
|
||||
#define BSWAP16(x) x = x
|
||||
#define BSWAP32(x) x = x
|
||||
#else
|
||||
#define bswap16(x) __builtin_bswap16(x)
|
||||
#define bswap32(x) __builtin_bswap32(x)
|
||||
#define BSWAP16(x) x = __builtin_bswap16(x)
|
||||
#define BSWAP32(x) x = __builtin_bswap32(x)
|
||||
#endif
|
||||
#define BSWAP16_MANY(x, n) for (s32 _i = 0; _i < n; _i++) BSWAP16((x)[_i])
|
||||
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
|
|
|
@ -15,8 +15,13 @@ typedef int s32;
|
|||
typedef unsigned char u8;
|
||||
typedef unsigned int u32;
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define BSWAP16(x)
|
||||
#define BSWAP32(x)
|
||||
#else
|
||||
#define BSWAP16(x) x = __builtin_bswap16(x)
|
||||
#define BSWAP32(x) x = __builtin_bswap32(x)
|
||||
#endif
|
||||
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#define UNUSED __attribute__((unused))
|
||||
|
|
|
@ -14,7 +14,7 @@ typedef unsigned long long u64;
|
|||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
#ifdef __sgi
|
||||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
# define BSWAP16(x)
|
||||
# define BSWAP32(x)
|
||||
# define BSWAP16_MANY(x, n)
|
||||
|
|
|
@ -82,6 +82,7 @@ void swap_bytes(unsigned char *data, long length)
|
|||
|
||||
void reverse_endian(unsigned char *data, long length)
|
||||
{
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
long i;
|
||||
unsigned char tmp;
|
||||
for (i = 0; i < length; i += 4) {
|
||||
|
@ -92,6 +93,7 @@ void reverse_endian(unsigned char *data, long length)
|
|||
data[i+1] = data[i+2];
|
||||
data[i+2] = tmp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
long filesize(const char *filename)
|
||||
|
|
Loading…
Reference in New Issue