UDK 3.2.7 C/C++ API Reference
osl/endian.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 
00029 #ifndef _OSL_ENDIAN_H_
00030 #define _OSL_ENDIAN_H_
00031 
00032 #include <sal/types.h>
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037 
00040 #ifdef _WIN32
00041 #   if defined(_M_IX86)
00042 #       define _LITTLE_ENDIAN
00043 #   elif defined(_M_AMD64)
00044 #       define _LITTLE_ENDIAN
00045 #   elif defined(_M_MRX000)
00046 #       define _LITTLE_ENDIAN
00047 #   elif defined(_M_ALPHA)
00048 #       define _LITTLE_ENDIAN
00049 #   elif defined(_M_PPC)
00050 #       define _LITTLE_ENDIAN
00051 #   endif
00052 #endif
00053 
00054 #ifdef LINUX
00055 #   include <endian.h>
00056 #   if __BYTE_ORDER == __LITTLE_ENDIAN
00057 #           ifndef _LITTLE_ENDIAN
00058 #       define _LITTLE_ENDIAN
00059 #           endif
00060 #   elif __BYTE_ORDER == __BIG_ENDIAN
00061 #           ifndef _BIG_ENDIAN
00062 #       define _BIG_ENDIAN
00063 #           endif
00064 #   endif
00065 #endif
00066 
00067 #ifdef ANDROID
00068 #   include <endian.h>
00069 #   if __BYTE_ORDER == __LITTLE_ENDIAN
00070 #           ifndef _LITTLE_ENDIAN
00071 #       define _LITTLE_ENDIAN
00072 #           endif
00073 #   elif __BYTE_ORDER == __BIG_ENDIAN
00074 #           ifndef _BIG_ENDIAN
00075 #       define _BIG_ENDIAN
00076 #           endif
00077 #   endif
00078 #endif
00079 
00080 #ifdef NETBSD
00081 #   include <machine/endian.h>
00082 #   if BYTE_ORDER == LITTLE_ENDIAN
00083 #   undef _BIG_ENDIAN
00084 #   elif BYTE_ORDER == BIG_ENDIAN
00085 #   undef _LITTLE_ENDIAN
00086 #   endif
00087 #endif
00088 
00089 #ifdef FREEBSD
00090 #   include <sys/param.h>
00091 #   include <machine/endian.h>
00092 #if __FreeBSD_version < 500000
00093 #   if BYTE_ORDER == LITTLE_ENDIAN
00094 #       define _LITTLE_ENDIAN
00095 #   elif BYTE_ORDER == BIG_ENDIAN
00096 #       define _BIG_ENDIAN
00097 #   endif
00098 #endif
00099 #endif
00100 
00101 #ifdef AIX
00102 #   include <sys/machine.h>
00103 #   if BYTE_ORDER == LITTLE_ENDIAN
00104 #       ifndef _LITTLE_ENDIAN
00105 #           define _LITTLE_ENDIAN
00106 #       endif
00107 #   elif BYTE_ORDER == BIG_ENDIAN
00108 #       ifndef _BIG_ENDIAN
00109 #           define _BIG_ENDIAN
00110 #       endif
00111 #   endif
00112 #endif
00113 
00114 #ifdef SOLARIS
00115 #   include <sys/isa_defs.h>
00116 #endif
00117 
00118 #ifdef MACOSX
00119 #   include <machine/endian.h>
00120 #   if BYTE_ORDER == LITTLE_ENDIAN
00121 #       ifndef _LITTLE_ENDIAN
00122 #       define _LITTLE_ENDIAN
00123 #       endif
00124 #   elif BYTE_ORDER == BIG_ENDIAN
00125 #       ifndef _BIG_ENDIAN
00126 #       define _BIG_ENDIAN
00127 #       endif
00128 #   endif
00129 #endif
00130 
00131 #ifdef IOS
00132 #   include <machine/endian.h>
00133 #   if BYTE_ORDER == LITTLE_ENDIAN
00134 #       ifndef _LITTLE_ENDIAN
00135 #       define _LITTLE_ENDIAN
00136 #       endif
00137 #   elif BYTE_ORDER == BIG_ENDIAN
00138 #       ifndef _BIG_ENDIAN
00139 #       define _BIG_ENDIAN
00140 #       endif
00141 #   endif
00142 #endif
00143 
00146 #if !defined(_WIN32)  && \
00147     !defined(LINUX)   && !defined(NETBSD) && \
00148     !defined(AIX)     && !defined(OPENBSD) && \
00149     !defined(SOLARIS) && !defined(MACOSX) && !defined(FREEBSD) && \
00150     !defined(DRAGONFLY) && \
00151     !defined(IOS)     && !defined(ANDROID)
00152 #   error "Target platform not specified !"
00153 #endif
00154 
00155 
00158 #if defined _LITTLE_ENDIAN
00159 #   define OSL_LITENDIAN
00160 #elif defined _BIG_ENDIAN
00161 #   define OSL_BIGENDIAN
00162 #else
00163 #   error undetermined endianess
00164 #endif
00165 
00166 
00169 #ifndef OSL_MAKEBYTE
00170 #   define OSL_MAKEBYTE(nl, nh)    ((sal_uInt8)(((nl) & 0x0F) | (((nh) & 0x0F) << 4)))
00171 #endif
00172 #ifndef OSL_LONIBBLE
00173 #   define OSL_LONIBBLE(b)         ((sal_uInt8)((b) & 0x0F))
00174 #endif
00175 #ifndef OSL_HINIBBLE
00176 #   define OSL_HINIBBLE(b)         ((sal_uInt8)(((b) >> 4) & 0x0F))
00177 #endif
00178 
00179 #ifndef OSL_MAKEWORD
00180 #   define OSL_MAKEWORD(bl, bh)    ((sal_uInt16)((bl) & 0xFF) | (((sal_uInt16)(bh) & 0xFF) << 8))
00181 #endif
00182 #ifndef OSL_LOBYTE
00183 #   define OSL_LOBYTE(w)           ((sal_uInt8)((sal_uInt16)(w) & 0xFF))
00184 #endif
00185 #ifndef OSL_HIBYTE
00186 #   define OSL_HIBYTE(w)           ((sal_uInt8)(((sal_uInt16)(w) >> 8) & 0xFF))
00187 #endif
00188 
00189 #ifndef OSL_MAKEDWORD
00190 #   define OSL_MAKEDWORD(wl, wh)   ((sal_uInt32)((wl) & 0xFFFF) | (((sal_uInt32)(wh) & 0xFFFF) << 16))
00191 #endif
00192 #ifndef OSL_LOWORD
00193 #   define OSL_LOWORD(d)           ((sal_uInt16)((sal_uInt32)(d) & 0xFFFF))
00194 #endif
00195 #ifndef OSL_HIWORD
00196 #   define OSL_HIWORD(d)           ((sal_uInt16)(((sal_uInt32)(d) >> 16) & 0xFFFF))
00197 #endif
00198 
00199 
00202 #ifdef OSL_BIGENDIAN
00203 #ifndef OSL_NETWORD
00204 #   define OSL_NETWORD(w)          (sal_uInt16)(w)
00205 #endif
00206 #ifndef OSL_NETDWORD
00207 #   define OSL_NETDWORD(d)         (sal_uInt32)(d)
00208 #endif
00209 #else  /* OSL_LITENDIAN */
00210 #ifndef OSL_NETWORD
00211 #   define OSL_NETWORD(w)          OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
00212 #endif
00213 #ifndef OSL_NETDWORD
00214 #   define OSL_NETDWORD(d)         OSL_MAKEDWORD(OSL_NETWORD(OSL_HIWORD(d)),OSL_NETWORD(OSL_LOWORD(d)))
00215 #endif
00216 #endif /* OSL_BIGENDIAN */
00217 
00218 
00221 #ifndef OSL_SWAPWORD
00222 #   define OSL_SWAPWORD(w)         OSL_MAKEWORD(OSL_HIBYTE(w),OSL_LOBYTE(w))
00223 #endif
00224 #ifndef OSL_SWAPDWORD
00225 #   define OSL_SWAPDWORD(d)        OSL_MAKEDWORD(OSL_SWAPWORD(OSL_HIWORD(d)),OSL_SWAPWORD(OSL_LOWORD(d)))
00226 #endif
00227 
00228 
00229 #ifdef __cplusplus
00230 }
00231 #endif
00232 
00233 #endif /*_OSL_ENDIAN_H_ */
00234 
00235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines