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

Diff of /navit/navit/endianess.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 30 Revision 31
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
1/** 20/**
2 * Navit, a modular navigation system. 21 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team 22 * Copyright (C) 2005-2008 Navit Team
4 * 23 *
5 * This program is free software; you can redistribute it and/or 24 * This program is free software; you can redistribute it and/or
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 35 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 36 * Boston, MA 02110-1301, USA.
18 */ 37 */
19#ifndef __ENDIANESS_HANDLER__ 38#ifndef __ENDIANESS_HANDLER__
20 39
21 /* The following is based on xorg/xserver/GL/glx/glxbyteorder.h 40/* 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 41 * 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 42 * BSD-license. All modifications in navit are licensed under the GNU GPL as
24 * described in file "COPYRIGHT". 43 * described in file "COPYRIGHT".
25 * 44 *
26 * Portions also from GNU C Library include/bits/byteswap.h Also licsend 45 * Portions also from GNU C Library include/bits/byteswap.h Also licsend
27 * under the GPL. 46 * under the GPL.
28 * 47 *
29 * -------------------------- 48 * --------------------------
30 * Permission is hereby granted, free of charge, to any person obtaining a 49 * Permission is hereby granted, free of charge, to any person obtaining a
31 * copy of this software and associated documentation files (the "Software"), 50 * copy of this software and associated documentation files (the "Software"),
32 * to deal in the Software without restriction, including without limitation 51 * to deal in the Software without restriction, including without limitation
33 * the rights to use, copy, modify, merge, publish, distribute, sub license, 52 * 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 53 * 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: 54 * Software is furnished to do so, subject to the following conditions:
36 * 55 *
37 * The above copyright notice and this permission notice (including the next 56 * The above copyright notice and this permission notice (including the next
38 * paragraph) shall be included in all copies or substantial portions of the 57 * paragraph) shall be included in all copies or substantial portions of the
39 * Software. 58 * Software.
40 * 59 *
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 60 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 61 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 62 * 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 63 * 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, 64 * 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 65 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
47 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 66 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48 */ 67 */
49#if HAVE_BYTESWAP_H 68#if HAVE_BYTESWAP_H
50 /* machine dependent versions of byte swapping functions. GNU extension.*/ 69/* machine dependent versions of byte swapping functions. GNU extension.*/
51 #include <byteswap.h> 70#include <byteswap.h>
52#elif defined(USE_SYS_ENDIAN_H) 71#elif defined(USE_SYS_ENDIAN_H)
53 #include <sys/endian.h> 72#include <sys/endian.h>
54#elif defined(__APPLE__) 73#elif defined(__APPLE__)
55 #include <libkern/OSByteOrder.h> 74#include <libkern/OSByteOrder.h>
56 #define __bswap_16 OSSwapInt16 75#define __bswap_16 OSSwapInt16
57 #define __bswap_32 OSSwapInt32 76#define __bswap_32 OSSwapInt32
58 #define __bswap_64 OSSwapInt64 77#define __bswap_64 OSSwapInt64
59 78
60#ifndef __BYTE_ORDER 79#ifndef __BYTE_ORDER
61 #define __LITTLE_ENDIAN 1234 80#define __LITTLE_ENDIAN 1234
62 #define __BIG_ENDIAN 4321 81#define __BIG_ENDIAN 4321
63 82
64 #if defined(__LITTLE_ENDIAN__) 83#if defined(__LITTLE_ENDIAN__)
65 #define __BYTE_ORDER __LITTLE_ENDIAN 84#define __BYTE_ORDER __LITTLE_ENDIAN
66 #elif defined(__BIG_ENDIAN__) 85#elif defined(__BIG_ENDIAN__)
67 #define __BYTE_ORDER __BIG_ENDIAN 86#define __BYTE_ORDER __BIG_ENDIAN
68 #else 87#else
69 #error "No endianness defined for Mac OS!" 88#error "No endianness defined for Mac OS!"
70 #endif 89#endif
71#endif 90#endif
72 91
73#elif defined(_WIN32) || defined(__CEGCC__) 92#elif defined(_WIN32) || defined(__CEGCC__)
74 #define __BIG_ENDIAN 4321 93#define __BIG_ENDIAN 4321
75 #define __LITTLE_ENDIAN 1234 94#define __LITTLE_ENDIAN 1234
76 #define __BYTE_ORDER __LITTLE_ENDIAN 95#define __BYTE_ORDER __LITTLE_ENDIAN
77#else 96#else
78 #define __bswap_16(__bsx) ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)) 97#define __bswap_16(__bsx) ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8))
79 #define __bswap_32(__bsx) ((((__bsx) & 0xff000000) >> 24) | \ 98#define __bswap_32(__bsx) ((((__bsx) & 0xff000000) >> 24) | \
80 (((__bsx) & 0x00ff0000) >> 8) |\ 99 (((__bsx) & 0x00ff0000) >> 8) |\
81 (((__bsx) & 0x0000ff00) << 8) | \ 100 (((__bsx) & 0x0000ff00) << 8) | \
82 (((__bsx) & 0x000000ff) << 24)) 101 (((__bsx) & 0x000000ff) << 24))
83 102
84
85#endif 103#endif
86 104
87#if __BYTE_ORDER == __BIG_ENDIAN 105#if __BYTE_ORDER == __BIG_ENDIAN
88 #define le16_to_cpu(x) __bswap_16 (x) 106#define le16_to_cpu(x) __bswap_16 (x)
89 #define le32_to_cpu(x) __bswap_32 (x) 107#define le32_to_cpu(x) __bswap_32 (x)
90 #define le64_to_cpu(x) __bswap_64 (x) 108#define le64_to_cpu(x) __bswap_64 (x)
91 #define cpu_to_le16(x) __bswap_16 (x) 109#define cpu_to_le16(x) __bswap_16 (x)
92 #define cpu_to_le32(x) __bswap_32 (x) 110#define cpu_to_le32(x) __bswap_32 (x)
93 #define cpu_to_le64(x) __bswap_64 (x) 111#define cpu_to_le64(x) __bswap_64 (x)
94#elif __BYTE_ORDER == __LITTLE_ENDIAN 112#elif __BYTE_ORDER == __LITTLE_ENDIAN
95 #define le16_to_cpu(x) (x) 113#define le16_to_cpu(x) (x)
96 #define le32_to_cpu(x) (x) 114#define le32_to_cpu(x) (x)
97 #define cpu_to_le16(x) (x) 115#define cpu_to_le16(x) (x)
98 #define cpu_to_le32(x) (x) 116#define cpu_to_le32(x) (x)
99#else 117#else
118// ------------------ ATTENTION !! CAUTION !! ---------
119// ------------------ ATTENTION !! CAUTION !! ---------
120// ------------------ ATTENTION !! CAUTION !! ---------
121//
100 #error "Unknown endianess" 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)
101#endif 131#endif
102 132
103#define __ENDIANESS_HANDLER__ 133#define __ENDIANESS_HANDLER__
104#endif 134#endif
105 135

Legend:
Removed from v.30  
changed lines
  Added in v.31

   
Visit the ZANavi Wiki