2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
19 #ifndef __ENDIANESS_HANDLER__
21 /* The following is based on xorg/xserver/GL/glx/glxbyteorder.h
22 * which is (c) IBM Corp. 2006,2007 and originally licensed under the following
23 * BSD-license. All modifications in navit are licensed under the GNU GPL as
24 * described in file "COPYRIGHT".
26 * Portions also from GNU C Library include/bits/byteswap.h Also licsend
29 * --------------------------
30 * Permission is hereby granted, free of charge, to any person obtaining a
31 * copy of this software and associated documentation files (the "Software"),
32 * to deal in the Software without restriction, including without limitation
33 * the rights to use, copy, modify, merge, publish, distribute, sub license,
34 * and/or sell copies of the Software, and to permit persons to whom the
35 * Software is furnished to do so, subject to the following conditions:
37 * The above copyright notice and this permission notice (including the next
38 * paragraph) shall be included in all copies or substantial portions of the
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
44 * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
45 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
46 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
47 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50 /* machine dependent versions of byte swapping functions. GNU extension.*/
55 #elif defined(USE_SYS_ENDIAN_H)
56 #include <sys/endian.h>
57 #if defined(_BYTE_ORDER) && !defined(__BYTE_ORDER)
58 #define __BYTE_ORDER _BYTE_ORDER
59 #define __LITTLE_ENDIAN _LITTLE_ENDIAN
60 #define __BIG_ENDIAN _BIG_ENDIAN
62 #elif defined(__APPLE__)
63 #include <libkern/OSByteOrder.h>
64 #define __bswap_16 OSSwapInt16
65 #define __bswap_32 OSSwapInt32
66 #define __bswap_64 OSSwapInt64
69 #define __LITTLE_ENDIAN 1234
70 #define __BIG_ENDIAN 4321
72 #if defined(__LITTLE_ENDIAN__)
73 #define __BYTE_ORDER __LITTLE_ENDIAN
74 #elif defined(__BIG_ENDIAN__)
75 #define __BYTE_ORDER __BIG_ENDIAN
77 #error "No endianness defined for Mac OS!"
81 #elif defined(_WIN32) || defined(__CEGCC__)
82 #define __BIG_ENDIAN 4321
83 #define __LITTLE_ENDIAN 1234
84 #define __BYTE_ORDER __LITTLE_ENDIAN
86 #define __bswap_16(__bsx) ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8))
87 #define __bswap_32(__bsx) ((((__bsx) & 0xff000000) >> 24) | \
88 (((__bsx) & 0x00ff0000) >> 8) |\
89 (((__bsx) & 0x0000ff00) << 8) | \
90 (((__bsx) & 0x000000ff) << 24))
95 #if __BYTE_ORDER == __BIG_ENDIAN
96 #define le16_to_cpu(x) __bswap_16 (x)
97 #define le32_to_cpu(x) __bswap_32 (x)
98 #define le64_to_cpu(x) __bswap_64 (x)
99 #define cpu_to_le16(x) __bswap_16 (x)
100 #define cpu_to_le32(x) __bswap_32 (x)
101 #define cpu_to_le64(x) __bswap_64 (x)
102 #elif __BYTE_ORDER == __LITTLE_ENDIAN
103 #define le16_to_cpu(x) (x)
104 #define le32_to_cpu(x) (x)
105 #define cpu_to_le16(x) (x)
106 #define cpu_to_le32(x) (x)
108 #error "Unknown endianess"
111 #define __ENDIANESS_HANDLER__