/[zanavi_public1]/navit/navit/endianess.h
ZANavi

Contents of /navit/navit/endianess.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Mon Feb 4 17:41:59 2013 UTC (11 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 5021 byte(s)
new map version, lots of fixes and experimental new features
1 /**
2 * ZANavi, Zoff Android Navigation system.
3 * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
8 *
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 General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * 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.
18 */
19
20 /**
21 * Navit, a modular navigation system.
22 * Copyright (C) 2005-2008 Navit Team
23 *
24 * This program is free software; you can redistribute it and/or
25 * modify it under the terms of the GNU Library General Public License
26 * version 2 as published by the Free Software Foundation.
27 *
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Library General Public License for more details.
32 *
33 * You should have received a copy of the GNU Library General Public
34 * License along with this program; if not, write to the
35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 * Boston, MA 02110-1301, USA.
37 */
38 #ifndef __ENDIANESS_HANDLER__
39
40 /* The following is based on xorg/xserver/GL/glx/glxbyteorder.h
41 * which is (c) IBM Corp. 2006,2007 and originally licensed under the following
42 * BSD-license. All modifications in navit are licensed under the GNU GPL as
43 * described in file "COPYRIGHT".
44 *
45 * Portions also from GNU C Library include/bits/byteswap.h Also licsend
46 * under the GPL.
47 *
48 * --------------------------
49 * Permission is hereby granted, free of charge, to any person obtaining a
50 * copy of this software and associated documentation files (the "Software"),
51 * to deal in the Software without restriction, including without limitation
52 * the rights to use, copy, modify, merge, publish, distribute, sub license,
53 * and/or sell copies of the Software, and to permit persons to whom the
54 * Software is furnished to do so, subject to the following conditions:
55 *
56 * The above copyright notice and this permission notice (including the next
57 * paragraph) shall be included in all copies or substantial portions of the
58 * Software.
59 *
60 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
61 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
62 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
63 * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
64 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
66 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67 */
68 #if HAVE_BYTESWAP_H
69 /* machine dependent versions of byte swapping functions. GNU extension.*/
70 #include <byteswap.h>
71 #elif defined(USE_SYS_ENDIAN_H)
72 #include <sys/endian.h>
73 #elif defined(__APPLE__)
74 #include <libkern/OSByteOrder.h>
75 #define __bswap_16 OSSwapInt16
76 #define __bswap_32 OSSwapInt32
77 #define __bswap_64 OSSwapInt64
78
79 #ifndef __BYTE_ORDER
80 #define __LITTLE_ENDIAN 1234
81 #define __BIG_ENDIAN 4321
82
83 #if defined(__LITTLE_ENDIAN__)
84 #define __BYTE_ORDER __LITTLE_ENDIAN
85 #elif defined(__BIG_ENDIAN__)
86 #define __BYTE_ORDER __BIG_ENDIAN
87 #else
88 #error "No endianness defined for Mac OS!"
89 #endif
90 #endif
91
92 #elif defined(_WIN32) || defined(__CEGCC__)
93 #define __BIG_ENDIAN 4321
94 #define __LITTLE_ENDIAN 1234
95 #define __BYTE_ORDER __LITTLE_ENDIAN
96 #else
97 #define __bswap_16(__bsx) ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8))
98 #define __bswap_32(__bsx) ((((__bsx) & 0xff000000) >> 24) | \
99 (((__bsx) & 0x00ff0000) >> 8) |\
100 (((__bsx) & 0x0000ff00) << 8) | \
101 (((__bsx) & 0x000000ff) << 24))
102
103 #endif
104
105 #if __BYTE_ORDER == __BIG_ENDIAN
106 #define le16_to_cpu(x) __bswap_16 (x)
107 #define le32_to_cpu(x) __bswap_32 (x)
108 #define le64_to_cpu(x) __bswap_64 (x)
109 #define cpu_to_le16(x) __bswap_16 (x)
110 #define cpu_to_le32(x) __bswap_32 (x)
111 #define cpu_to_le64(x) __bswap_64 (x)
112 #elif __BYTE_ORDER == __LITTLE_ENDIAN
113 #define le16_to_cpu(x) (x)
114 #define le32_to_cpu(x) (x)
115 #define cpu_to_le16(x) (x)
116 #define cpu_to_le32(x) (x)
117 #else
118 // ------------------ ATTENTION !! CAUTION !! ---------
119 // ------------------ ATTENTION !! CAUTION !! ---------
120 // ------------------ ATTENTION !! CAUTION !! ---------
121 //
122 // #error "Unknown endianess"
123 // set LITTLE ENDIAN as default!!!!!!
124 //
125 // ------------------ ATTENTION !! CAUTION !! ---------
126 // ------------------ ATTENTION !! CAUTION !! ---------
127 #define le16_to_cpu(x) (x)
128 #define le32_to_cpu(x) (x)
129 #define cpu_to_le16(x) (x)
130 #define cpu_to_le32(x) (x)
131 #endif
132
133 #define __ENDIANESS_HANDLER__
134 #endif
135

   
Visit the ZANavi Wiki