blob: c890fd721d53048873952bfa54d014b853c7e91e [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
26#else
27#include <endian.h>
28 #if __BYTE_ORDER == __LITTLE_ENDIAN
29 #define OSMO_IS_LITTLE_ENDIAN 1
30 #define OSMO_IS_BIG_ENDIAN 0
31 #elif __BYTE_ORDER == __BIG_ENDIAN
32 #define OSMO_IS_LITTLE_ENDIAN 0
33 #define OSMO_IS_BIG_ENDIAN 1
34 #else
35 #error "Unknown endian"
36 #endif
37#endif
38