HACKING.asciidoc: update Windows cross-build section to use libav10
[libam7xxx.git] / src / portable_endian.h
1 /* 
2  * Public domain, stripped down version of:
3  * https://gist.github.com/panzi/6856583
4  */
5
6 #ifndef __PORTABLE_ENDIAN_H
7 #define __PORTABLE_ENDIAN_H
8
9 #if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
10
11 #       define __WINDOWS__
12
13 #endif
14
15 #if defined(__linux__) || defined(__CYGWIN__)
16
17 #       include <endian.h>
18
19 #elif defined(__APPLE__)
20
21 #       include <libkern/OSByteOrder.h>
22
23 #       define htole32(x) OSSwapHostToLittleInt32(x)
24 #       define le32toh(x) OSSwapLittleToHostInt32(x)
25
26 #elif defined(__OpenBSD__)
27
28 #       include <sys/endian.h>
29
30 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
31
32 #       include <sys/endian.h>
33
34 #       define le32toh(x) letoh32(x)
35
36 #elif defined(__WINDOWS__)
37
38 #       include <winsock2.h>
39 #       include <sys/param.h>
40
41 #       if BYTE_ORDER == LITTLE_ENDIAN
42
43 #               define htole32(x) (x)
44 #               define le32toh(x) (x)
45
46 #       elif BYTE_ORDER == BIG_ENDIAN
47
48                 /* that would be xbox 360 */
49
50 #               define htole32(x) __builtin_bswap32(x)
51 #               define le32toh(x) __builtin_bswap32(x)
52
53 #       else
54
55 #               error byte order not supported
56
57 #       endif
58
59 #else
60
61 #error platform not supported
62
63 #endif
64
65 #endif /* __PORTABLE_ENDIAN_H */