Holger Hans Peter Freyther | 249a81b | 2015-03-22 09:03:42 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | /** |
| 4 | * GNU and FreeBSD have various ways to express the |
| 5 | * endianess but none of them is similiar enough. This |
| 6 | * will create two defines that allows to decide on the |
| 7 | * endian. The following will be defined to either 0 or |
| 8 | * 1 at the end of the file. |
| 9 | * |
| 10 | * OSMO_IS_LITTLE_ENDIAN |
| 11 | * OSMO_IS_BIG_ENDIAN |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #if defined(__FreeBSD__) |
| 16 | #include <sys/endian.h> |
| 17 | #if BYTE_ORDER == LITTLE_ENDIAN |
| 18 | #define OSMO_IS_LITTLE_ENDIAN 1 |
| 19 | #define OSMO_IS_BIG_ENDIAN 0 |
| 20 | #elif BYTE_ORDER == BIG_ENDIAN |
| 21 | #define OSMO_IS_LITTLE_ENDIAN 0 |
| 22 | #define OSMO_IS_BIG_ENDIAN 1 |
| 23 | #else |
| 24 | #error "Unknown endian" |
| 25 | #endif |
Arran Cudbard-Bell | cc3694b | 2016-05-18 16:02:19 -0400 | [diff] [blame] | 26 | #elif defined(__APPLE__) |
| 27 | #include <machine/endian.h> |
| 28 | #if defined(__DARWIN_LITTLE_ENDIAN) |
| 29 | #define OSMO_IS_LITTLE_ENDIAN 1 |
| 30 | #define OSMO_IS_BIG_ENDIAN 0 |
Beshr Al Nahas | e4c294f | 2016-05-28 14:21:13 +0200 | [diff] [blame] | 31 | #elif defined(__DARWIN_BIG_ENDIAN) |
Arran Cudbard-Bell | cc3694b | 2016-05-18 16:02:19 -0400 | [diff] [blame] | 32 | #define OSMO_IS_LITTLE_ENDIAN 0 |
| 33 | #define OSMO_IS_BIG_ENDIAN 1 |
| 34 | #else |
| 35 | #error "Unknown endian" |
| 36 | #endif |
Holger Hans Peter Freyther | 249a81b | 2015-03-22 09:03:42 +0100 | [diff] [blame] | 37 | #else |
| 38 | #include <endian.h> |
| 39 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 40 | #define OSMO_IS_LITTLE_ENDIAN 1 |
| 41 | #define OSMO_IS_BIG_ENDIAN 0 |
| 42 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 43 | #define OSMO_IS_LITTLE_ENDIAN 0 |
| 44 | #define OSMO_IS_BIG_ENDIAN 1 |
| 45 | #else |
| 46 | #error "Unknown endian" |
| 47 | #endif |
| 48 | #endif |
| 49 | |