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.
20 #ifndef __ENDIANESS_HANDLER__
22 /* The following is based on xorg/xserver/GL/glx/glxbyteorder.h
23 * which is (c) IBM Corp. 2006,2007 and originally licensed under the following
24 * BSD-license. All modifications in navit are licensed under the GNU GPL as
25 * described in file "COPYRIGHT".
26 * --------------------------
27 * Permission is hereby granted, free of charge, to any person obtaining a
28 * copy of this software and associated documentation files (the "Software"),
29 * to deal in the Software without restriction, including without limitation
30 * the rights to use, copy, modify, merge, publish, distribute, sub license,
31 * and/or sell copies of the Software, and to permit persons to whom the
32 * Software is furnished to do so, subject to the following conditions:
34 * The above copyright notice and this permission notice (including the next
35 * paragraph) shall be included in all copies or substantial portions of the
38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
41 * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
42 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
43 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
44 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 /* machine dependent versions of byte swapping functions. GNU extension.*/
50 #elif defined(USE_SYS_ENDIAN_H)
51 #include <sys/endian.h>
52 #elif defined(__APPLE__)
53 #include <libkern/OSByteOrder.h>
54 #define __bswap_16 OSSwapInt16
55 #define __bswap_32 OSSwapInt32
56 #define __bswap_64 OSSwapInt64
58 #define __bswap_16(value) \
59 ((((value) & 0xff) << 8) | ((value) >> 8))
60 #define __bswap_32(value) \
61 (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
62 (uint32_t)bswap_16((uint16_t)((value) >> 16)))
63 #define __bswap_64(value) \
64 (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
66 (uint64_t)bswap_32((uint32_t)((value) >> 32)))
69 #if __BYTE_ORDER == __BIG_ENDIAN
70 #define le16_to_cpu(x) __bswap_16 (x)
71 #define le32_to_cpu(x) __bswap_32 (x)
72 #define le64_to_cpu(x) __bswap_64 (x)
73 #define cpu_to_le16(x) __bswap_16 (x)
74 #define cpu_to_le32(x) __bswap_32 (x)
75 #define cpu_to_le64(x) __bswap_64 (x)
76 #elif __BYTE_ORDER == __LITTLE_ENDIAN
77 #define le16_to_cpu(x) (x)
78 #define le32_to_cpu(x) (x)
79 #define cpu_to_le16(x) (x)
80 #define cpu_to_le16(x) (x)
82 #error "Unknown endianess"
85 #define __ENDIANESS_HANDLER__