00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _OSL_ENDIAN_H_
00021 #define _OSL_ENDIAN_H_
00022
00023 #include <sal/types.h>
00024
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028
00031 #ifdef _WIN32
00032 # if defined(_M_IX86)
00033 # define _LITTLE_ENDIAN
00034 # elif defined(_M_AMD64)
00035 # define _LITTLE_ENDIAN
00036 # elif defined(_M_MRX000)
00037 # define _LITTLE_ENDIAN
00038 # elif defined(_M_ALPHA)
00039 # define _LITTLE_ENDIAN
00040 # elif defined(_M_PPC)
00041 # define _LITTLE_ENDIAN
00042 # endif
00043 #endif
00044
00045 #ifdef LINUX
00046 # include <endian.h>
00047 # if __BYTE_ORDER == __LITTLE_ENDIAN
00048 # ifndef _LITTLE_ENDIAN
00049 # define _LITTLE_ENDIAN
00050 # endif
00051 # elif __BYTE_ORDER == __BIG_ENDIAN
00052 # ifndef _BIG_ENDIAN
00053 # define _BIG_ENDIAN
00054 # endif
00055 # endif
00056 #endif
00057
00058 #ifdef ANDROID
00059 # include <endian.h>
00060 # if __BYTE_ORDER == __LITTLE_ENDIAN
00061 # ifndef _LITTLE_ENDIAN
00062 # define _LITTLE_ENDIAN
00063 # endif
00064 # elif __BYTE_ORDER == __BIG_ENDIAN
00065 # ifndef _BIG_ENDIAN
00066 # define _BIG_ENDIAN
00067 # endif
00068 # endif
00069 #endif
00070
00071 #ifdef NETBSD
00072 # include <machine/endian.h>
00073 # if BYTE_ORDER == LITTLE_ENDIAN
00074 # undef _BIG_ENDIAN
00075 # elif BYTE_ORDER == BIG_ENDIAN
00076 # undef _LITTLE_ENDIAN
00077 # endif
00078 #endif
00079
00080 #ifdef FREEBSD
00081 # include <sys/param.h>
00082 # include <machine/endian.h>
00083 #if __FreeBSD_version < 500000
00084 # if BYTE_ORDER == LITTLE_ENDIAN
00085 # define _LITTLE_ENDIAN
00086 # elif BYTE_ORDER == BIG_ENDIAN
00087 # define _BIG_ENDIAN
00088 # endif
00089 #endif
00090 #endif
00091
00092 #ifdef AIX
00093 # include <sys/machine.h>
00094 # if BYTE_ORDER == LITTLE_ENDIAN
00095 # ifndef _LITTLE_ENDIAN
00096 # define _LITTLE_ENDIAN
00097 # endif
00098 # elif BYTE_ORDER == BIG_ENDIAN
00099 # ifndef _BIG_ENDIAN
00100 # define _BIG_ENDIAN
00101 # endif
00102 # endif
00103 #endif
00104
00105 #ifdef SOLARIS
00106 # include <sys/isa_defs.h>
00107 #endif
00108
00109 #ifdef MACOSX
00110 # include <machine/endian.h>
00111 # if BYTE_ORDER == LITTLE_ENDIAN
00112 # ifndef _LITTLE_ENDIAN
00113 # define _LITTLE_ENDIAN
00114 # endif
00115 # elif BYTE_ORDER == BIG_ENDIAN
00116 # ifndef _BIG_ENDIAN
00117 # define _BIG_ENDIAN
00118 # endif
00119 # endif
00120 #endif
00121
00122 #ifdef IOS
00123 # include <machine/endian.h>
00124 # if BYTE_ORDER == LITTLE_ENDIAN
00125 # ifndef _LITTLE_ENDIAN
00126 # define _LITTLE_ENDIAN
00127 # endif
00128 # elif BYTE_ORDER == BIG_ENDIAN
00129 # ifndef _BIG_ENDIAN
00130 # define _BIG_ENDIAN
00131 # endif
00132 # endif
00133 #endif
00134
00137 #if !defined(_WIN32) && \
00138 !defined(LINUX) && !defined(NETBSD) && \
00139 !defined(AIX) && !defined(OPENBSD) && \
00140 !defined(SOLARIS) && !defined(MACOSX) && !defined(FREEBSD) && \
00141 !defined(DRAGONFLY) && \
00142 !defined(IOS) && !defined(ANDROID)
00143 # error "Target platform not specified !"
00144 #endif
00145
00146
00149 #if defined _LITTLE_ENDIAN
00150 # define OSL_LITENDIAN
00151 #elif defined _BIG_ENDIAN
00152 # define OSL_BIGENDIAN
00153 #else
00154 # error undetermined endianess
00155 #endif
00156
00157
00160 #ifndef OSL_MAKEBYTE
00161 # define OSL_MAKEBYTE(nl, nh) ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4)))
00162 #endif
00163 #ifndef OSL_LONIBBLE
00164 # define OSL_LONIBBLE(b) ((sal_uInt8)((b) & 0x0F))
00165 #endif
00166 #ifndef OSL_HINIBBLE
00167 # define OSL_HINIBBLE(b) ((sal_uInt8)(((b) >> 4) & 0x0F))
00168 #endif
00169
00170 #ifndef OSL_MAKEWORD
00171 # define OSL_MAKEWORD(bl, bh) ((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8))
00172 #endif
00173 #ifndef OSL_LOBYTE
00174 # define OSL_LOBYTE(w) ((sal_uInt8)((sal_uInt16)(w) & 0xFF))
00175 #endif
00176 #ifndef OSL_HIBYTE
00177 # define OSL_HIBYTE(w) ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF))
00178 #endif
00179
00180 #ifndef OSL_MAKEDWORD
00181 # define OSL_MAKEDWORD(wl, wh) ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16))
00182 #endif
00183 #ifndef OSL_LOWORD
00184 # define OSL_LOWORD(d) ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF))
00185 #endif
00186 #ifndef OSL_HIWORD
00187 # define OSL_HIWORD(d) ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF))
00188 #endif
00189
00190
00193 #ifdef OSL_BIGENDIAN
00194 #ifndef OSL_NETWORD
00195 # define OSL_NETWORD(w) (sal_uInt16)(w)
00196 #endif
00197 #ifndef OSL_NETDWORD
00198 # define OSL_NETDWORD(d) (sal_uInt32)(d)
00199 #endif
00200 #else
00201 #ifndef OSL_NETWORD
00202 # define OSL_NETWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
00203 #endif
00204 #ifndef OSL_NETDWORD
00205 # define OSL_NETDWORD(d) OSL_MAKEDWORD(OSL_NETWORD(OSL_HIWORD(d)),OSL_NETWORD(OSL_LOWORD(d)))
00206 #endif
00207 #endif
00208
00209
00212 #ifndef OSL_SWAPWORD
00213 # define OSL_SWAPWORD(w) OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
00214 #endif
00215 #ifndef OSL_SWAPDWORD
00216 # define OSL_SWAPDWORD(d) OSL_MAKEDWORD(OSL_SWAPWORD(OSL_HIWORD(d)),OSL_SWAPWORD(OSL_LOWORD(d)))
00217 #endif
00218
00219
00220 #ifdef __cplusplus
00221 }
00222 #endif
00223
00224 #endif
00225
00226