2017-06-20 02:35:06 +00:00
|
|
|
/*! \file endian.h
|
|
|
|
*
|
2015-03-22 08:03:42 +00:00
|
|
|
* GNU and FreeBSD have various ways to express the
|
|
|
|
* endianess but none of them is similiar enough. This
|
|
|
|
* will create two defines that allows to decide on the
|
|
|
|
* endian. The following will be defined to either 0 or
|
|
|
|
* 1 at the end of the file.
|
|
|
|
*
|
|
|
|
* OSMO_IS_LITTLE_ENDIAN
|
|
|
|
* OSMO_IS_BIG_ENDIAN
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-06-20 02:35:06 +00:00
|
|
|
#pragma once
|
|
|
|
|
2015-03-22 08:03:42 +00:00
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
#include <sys/endian.h>
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
|
|
#define OSMO_IS_LITTLE_ENDIAN 1
|
|
|
|
#define OSMO_IS_BIG_ENDIAN 0
|
|
|
|
#elif BYTE_ORDER == BIG_ENDIAN
|
|
|
|
#define OSMO_IS_LITTLE_ENDIAN 0
|
|
|
|
#define OSMO_IS_BIG_ENDIAN 1
|
|
|
|
#else
|
|
|
|
#error "Unknown endian"
|
|
|
|
#endif
|
2016-05-18 20:02:19 +00:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
#include <machine/endian.h>
|
|
|
|
#if defined(__DARWIN_LITTLE_ENDIAN)
|
|
|
|
#define OSMO_IS_LITTLE_ENDIAN 1
|
|
|
|
#define OSMO_IS_BIG_ENDIAN 0
|
2016-05-28 12:21:13 +00:00
|
|
|
#elif defined(__DARWIN_BIG_ENDIAN)
|
2016-05-18 20:02:19 +00:00
|
|
|
#define OSMO_IS_LITTLE_ENDIAN 0
|
|
|
|
#define OSMO_IS_BIG_ENDIAN 1
|
|
|
|
#else
|
|
|
|
#error "Unknown endian"
|
|
|
|
#endif
|
2017-05-15 09:44:39 +00:00
|
|
|
#elif defined(__linux__)
|
2015-03-22 08:03:42 +00:00
|
|
|
#include <endian.h>
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
|
#define OSMO_IS_LITTLE_ENDIAN 1
|
|
|
|
#define OSMO_IS_BIG_ENDIAN 0
|
|
|
|
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
#define OSMO_IS_LITTLE_ENDIAN 0
|
|
|
|
#define OSMO_IS_BIG_ENDIAN 1
|
|
|
|
#else
|
|
|
|
#error "Unknown endian"
|
|
|
|
#endif
|
2017-05-15 09:44:39 +00:00
|
|
|
#else
|
|
|
|
/* let's try to rely on the compiler. GCC and CLANG/LLVM seem
|
|
|
|
* to support this ... */
|
|
|
|
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
|
|
|
#define OSMO_IS_LITTLE_ENDIAN 1
|
|
|
|
#define OSMO_IS_BIG_ENDIAN 0
|
|
|
|
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
|
|
|
#define OSMO_IS_LITTLE_ENDIAN 0
|
|
|
|
#define OSMO_IS_BIG_ENDIAN 1
|
|
|
|
#else
|
|
|
|
#error "Unknown endian"
|
|
|
|
#endif
|
2015-03-22 08:03:42 +00:00
|
|
|
#endif
|
|
|
|
|