Fix:maptool:Another name for faroe islands
[navit-package] / navit / endianess.h
1 /**
2  * Navit, a modular navigation system.
3  * Copyright (C) 2005-2008 Navit Team
4  *
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.
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 Library General Public License for more details.
13  *
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.
18  */
19 #ifndef __ENDIANESS_HANDLER__
20
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".
25    *
26    * Portions also from GNU C Library include/bits/byteswap.h Also licsend
27    * under the GPL.
28    *
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:
36    * 
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
39    * Software.
40    * 
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.
48    */
49 #if HAVE_BYTESWAP_H
50   /* machine dependent versions of byte swapping functions.  GNU extension.*/
51   #include <byteswap.h>
52 #elif defined(USE_SYS_ENDIAN_H)
53   #include <sys/endian.h>
54 #elif defined(__APPLE__)
55   #include <libkern/OSByteOrder.h>
56   #define __bswap_16 OSSwapInt16
57   #define __bswap_32 OSSwapInt32
58   #define __bswap_64 OSSwapInt64
59
60 #ifndef __BYTE_ORDER
61   #define __LITTLE_ENDIAN 1234
62   #define __BIG_ENDIAN 4321
63
64   #if defined(__LITTLE_ENDIAN__)
65     #define __BYTE_ORDER __LITTLE_ENDIAN
66   #elif defined(__BIG_ENDIAN__)
67     #define __BYTE_ORDER __BIG_ENDIAN
68   #else
69     #error "No endianness defined for Mac OS!"
70   #endif
71 #endif
72
73 #elif  defined(_WIN32) || defined(__CEGCC__)
74   #define __BIG_ENDIAN 4321
75   #define __LITTLE_ENDIAN 1234
76   #define __BYTE_ORDER __LITTLE_ENDIAN
77 #else
78   #define __bswap_16(__bsx) ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8))
79   #define __bswap_32(__bsx) ((((__bsx) & 0xff000000) >> 24) | \
80                              (((__bsx) & 0x00ff0000) >>  8) |\
81                              (((__bsx) & 0x0000ff00) <<  8) | \
82                              (((__bsx) & 0x000000ff) << 24))
83
84
85 #endif
86
87 #if  __BYTE_ORDER == __BIG_ENDIAN 
88   #define le16_to_cpu(x)        __bswap_16 (x)
89   #define le32_to_cpu(x)        __bswap_32 (x)
90   #define le64_to_cpu(x)        __bswap_64 (x)
91   #define cpu_to_le16(x)        __bswap_16 (x)
92   #define cpu_to_le32(x)        __bswap_32 (x)
93   #define cpu_to_le64(x)        __bswap_64 (x)
94 #elif __BYTE_ORDER == __LITTLE_ENDIAN 
95   #define le16_to_cpu(x)        (x)
96   #define le32_to_cpu(x)        (x)
97   #define cpu_to_le16(x)        (x)
98   #define cpu_to_le32(x)        (x)
99 #else
100   #error "Unknown endianess"
101 #endif
102
103 #define __ENDIANESS_HANDLER__
104 #endif
105