File: endian.h

package info (click to toggle)
faifa 0.2~svn82-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 308 kB
  • sloc: ansic: 3,523; sh: 169; makefile: 94
file content (51 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef __endian_compat_h
#define __endian_compat_h

#if defined(__linux__) || defined(__GNU__)
#include <byteswap.h>
#include_next <endian.h>
#elif defined(__APPLE__)
#include <machine/endian.h>
#include <machine/byte_order.h>
#define bswap_16(x) NXSwapShort(x)
#define bswap_32(x) NXSwapInt(x)
#define bswap_64(x) NXSwapLongLong(x)
#elif defined(__FreeBSD__)
#include <sys/endian.h>
#define bswap_16(x) bswap16(x)
#define bswap_32(x) bswap32(x)
#define bswap_64(x) bswap64(x)
#else
#include <machine/endian.h>
#define bswap_16(x) swap16(x)
#define bswap_32(x) swap32(x)
#define bswap_64(x) swap64(x)
#endif

#ifndef __BYTE_ORDER
#define __BYTE_ORDER BYTE_ORDER
#endif
#ifndef __BIG_ENDIAN
#define __BIG_ENDIAN BIG_ENDIAN
#endif
#ifndef __LITTLE_ENDIAN
#define __LITTLE_ENDIAN LITTLE_ENDIAN
#endif

#if __BYTE_ORDER == __BIG_ENDIAN
#define STORE32_LE(X)           bswap_32(X)
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#define STORE32_LE(X)           (X)
#else
#error unkown endianness!
#endif

#if __BYTE_ORDER == __BIG_ENDIAN
#define STORE16_LE(X)           bswap_16(X)
#elif __BYTE_ORDER == __LITTLE_ENDIAN
#define STORE16_LE(X)           (X)
#else
#error unkown endianness!
#endif

#endif