00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 #ifndef _endianness_h
00061 #define _endianness_h
00062
00063
00064 #include <sys/types.h>
00065 #include <sys/param.h>
00066
00067
00068
00069 extern int _endian_test_int;
00070
00071
00072 #define endian_test() (*(char*)&_endian_test_int==1)
00073 #define is_big_endian() (!endian_test())
00074 #define is_little_endian() endian_test()
00075
00076
00077 extern int endianness_sanity_check();
00078
00079
00080 #if defined __BYTE_ORDER && defined __LITTLE_ENDIAN && defined __BIG_ENDIAN
00081
00082 #if __BYTE_ORDER == __LITTLE_ENDIAN && ! defined __IS_LITTLE_ENDIAN
00083 #define __IS_LITTLE_ENDIAN 0x01020304
00084 #endif
00085 #if __BYTE_ORDER == __BIG_ENDIAN && ! defined __IS_BIG_ENDIAN
00086 #define __IS_BIG_ENDIAN 0x01020304
00087 #endif
00088 #elif defined _BYTE_ORDER && defined _LITTLE_ENDIAN && defined _BIG_ENDIAN
00089
00090 #if _BYTE_ORDER == _LITTLE_ENDIAN && ! defined __IS_LITTLE_ENDIAN
00091 #define __IS_LITTLE_ENDIAN 0x01020304
00092 #endif
00093 #if _BYTE_ORDER == _BIG_ENDIAN && ! defined __IS_BIG_ENDIAN
00094 #define __IS_BIG_ENDIAN 0x01020304
00095 #endif
00096 #elif defined BYTE_ORDER && defined LITTLE_ENDIAN && defined BIG_ENDIAN
00097
00098 #if BYTE_ORDER == LITTLE_ENDIAN && ! defined __IS_LITTLE_ENDIAN
00099 #define __IS_LITTLE_ENDIAN 0x01020304
00100 #endif
00101 #if BYTE_ORDER == BIG_ENDIAN && ! defined __IS_BIG_ENDIAN
00102 #define __IS_BIG_ENDIAN 0x01020304
00103 #endif
00104 #elif !(defined _LITTLE_ENDIAN && defined _BIG_ENDIAN) && \
00105 (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
00106
00107
00108
00109 #if defined _LITTLE_ENDIAN && !defined __IS_LITTLE_ENDIAN
00110 #define __IS_LITTLE_ENDIAN 0x01020304
00111 #endif
00112 #if defined _BIG_ENDIAN && !defined __IS_BIG_ENDIAN
00113 #define __IS_BIG_ENDIAN 0x04030201
00114 #endif
00115 #elif !(defined LITTLE_ENDIAN && defined BIG_ENDIAN) && \
00116 (defined LITTLE_ENDIAN || defined BIG_ENDIAN)
00117
00118
00119 #if defined LITTLE_ENDIAN && !defined __IS_LITTLE_ENDIAN
00120 #define __IS_LITTLE_ENDIAN 0x01020304
00121 #endif
00122 #if defined BIG_ENDIAN && !defined __IS_BIG_ENDIAN
00123 #define __IS_BIG_ENDIAN 0x04030201
00124 #endif
00125
00126 #else
00127 #error could not detect endianess
00128 #endif
00129
00130 #if !defined __IS_LITTLE_ENDIAN && !defined __IS_BIG_ENDIAN
00131 #error BUG: could not detect endianess
00132 #endif
00133
00134 #if defined __IS_LITTLE_ENDIAN && defined __IS_BIG_ENDIAN
00135 #error BUG: both little & big endian detected in the same time
00136 #endif
00137
00138
00139 #endif
00140