Navit SVN

/work/compile/navit/src/navit/endianess.h

00001 
00019 #ifndef __ENDIANESS_HANDLER__
00020 
00021   /* The following is based on xorg/xserver/GL/glx/glxbyteorder.h 
00022    * which is (c) IBM Corp. 2006,2007 and originally licensed under the following
00023    * BSD-license. All modifications in navit are licensed under the GNU GPL as 
00024    * described in file "COPYRIGHT".
00025    *
00026    * Portions also from GNU C Library include/bits/byteswap.h Also licsend
00027    * under the GPL.
00028    *
00029    * --------------------------
00030    * Permission is hereby granted, free of charge, to any person obtaining a
00031    * copy of this software and associated documentation files (the "Software"),
00032    * to deal in the Software without restriction, including without limitation
00033    * the rights to use, copy, modify, merge, publish, distribute, sub license,
00034    * and/or sell copies of the Software, and to permit persons to whom the
00035    * Software is furnished to do so, subject to the following conditions:
00036    * 
00037    * The above copyright notice and this permission notice (including the next
00038    * paragraph) shall be included in all copies or substantial portions of the
00039    * Software.
00040    * 
00041    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00042    * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00043    * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
00044    * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
00045    * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00046    * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
00047    * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00048    */
00049 #if HAVE_BYTESWAP_H
00050   /* machine dependent versions of byte swapping functions.  GNU extension.*/
00051   #include <byteswap.h>
00052 #if HAVE_ENDIAN_H
00053   #include <endian.h>
00054 #endif
00055 #elif defined(USE_SYS_ENDIAN_H)
00056   #include <sys/endian.h>
00057 #if defined(_BYTE_ORDER) && !defined(__BYTE_ORDER)
00058 #define __BYTE_ORDER _BYTE_ORDER
00059 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
00060 #define __BIG_ENDIAN _BIG_ENDIAN
00061 #endif
00062 #elif defined(__APPLE__)
00063   #include <libkern/OSByteOrder.h>
00064   #define __bswap_16 OSSwapInt16
00065   #define __bswap_32 OSSwapInt32
00066   #define __bswap_64 OSSwapInt64
00067 
00068 #ifndef __BYTE_ORDER
00069   #define __LITTLE_ENDIAN 1234
00070   #define __BIG_ENDIAN 4321
00071 
00072   #if defined(__LITTLE_ENDIAN__)
00073     #define __BYTE_ORDER __LITTLE_ENDIAN
00074   #elif defined(__BIG_ENDIAN__)
00075     #define __BYTE_ORDER __BIG_ENDIAN
00076   #else
00077     #error "No endianness defined for Mac OS!"
00078   #endif
00079 #endif
00080 
00081 #elif  defined(_WIN32) || defined(__CEGCC__)
00082   #define __BIG_ENDIAN 4321
00083   #define __LITTLE_ENDIAN 1234
00084   #define __BYTE_ORDER __LITTLE_ENDIAN
00085 #else
00086   #define __bswap_16(__bsx) ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8))
00087   #define __bswap_32(__bsx) ((((__bsx) & 0xff000000) >> 24) | \
00088                              (((__bsx) & 0x00ff0000) >>  8) |\
00089                              (((__bsx) & 0x0000ff00) <<  8) | \
00090                              (((__bsx) & 0x000000ff) << 24))
00091 
00092 
00093 #endif
00094 
00095 #if  __BYTE_ORDER == __BIG_ENDIAN 
00096   #define le16_to_cpu(x)        __bswap_16 (x)
00097   #define le32_to_cpu(x)        __bswap_32 (x)
00098   #define le64_to_cpu(x)        __bswap_64 (x)
00099   #define cpu_to_le16(x)        __bswap_16 (x)
00100   #define cpu_to_le32(x)        __bswap_32 (x)
00101   #define cpu_to_le64(x)        __bswap_64 (x)
00102 #elif __BYTE_ORDER == __LITTLE_ENDIAN 
00103   #define le16_to_cpu(x)        (x)
00104   #define le32_to_cpu(x)        (x)
00105   #define cpu_to_le16(x)        (x)
00106   #define cpu_to_le32(x)        (x)
00107 #else
00108   #error "Unknown endianess"
00109 #endif
00110 
00111 #define __ENDIANESS_HANDLER__
00112 #endif
00113