blob: 02c6406dfba92bd18d3b9f7d5da55406b99b033c [file] [log] [blame]
Holger Hans Peter Freyther249a81b2015-03-22 09:03:42 +01001#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-Bellcc3694b2016-05-18 16:02:19 -040026#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
31 #elif define(__DARWIN_BIG_ENDIAN)
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 Freyther249a81b2015-03-22 09:03:42 +010037#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