navit 0.5.3-trunk
Loading...
Searching...
No Matches
endianess.h
Go to the documentation of this file.
1
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# if HAVE_ENDIAN_H
53# include <endian.h>
54# endif
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
61# endif
62# elif defined(__APPLE__)
63# include <libkern/OSByteOrder.h>
64# define __bswap_16 OSSwapInt16
65# define __bswap_32 OSSwapInt32
66# define __bswap_64 OSSwapInt64
67
68# ifndef __BYTE_ORDER
69# define __LITTLE_ENDIAN 1234
70# define __BIG_ENDIAN 4321
71
72# if defined(__LITTLE_ENDIAN__)
73# define __BYTE_ORDER __LITTLE_ENDIAN
74# elif defined(__BIG_ENDIAN__)
75# define __BYTE_ORDER __BIG_ENDIAN
76# else
77# error "No endianness defined for Mac OS!"
78# endif
79# endif
80
81# elif defined(_WIN32) || defined(__CEGCC__)
82# define __BIG_ENDIAN 4321
83# define __LITTLE_ENDIAN 1234
84# define __BYTE_ORDER __LITTLE_ENDIAN
85# else
86# define __bswap_16(__bsx) ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8))
87# define __bswap_32(__bsx) \
88 ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | (((__bsx) & 0x0000ff00) << 8) \
89 | (((__bsx) & 0x000000ff) << 24))
90
91# endif
92
93# if __BYTE_ORDER == __BIG_ENDIAN
94# define le16_to_cpu(x) __bswap_16(x)
95# define le32_to_cpu(x) __bswap_32(x)
96# define le64_to_cpu(x) __bswap_64(x)
97# define cpu_to_le16(x) __bswap_16(x)
98# define cpu_to_le32(x) __bswap_32(x)
99# define cpu_to_le64(x) __bswap_64(x)
100# elif __BYTE_ORDER == __LITTLE_ENDIAN
101# define le16_to_cpu(x) (x)
102# define le32_to_cpu(x) (x)
103# define cpu_to_le16(x) (x)
104# define cpu_to_le32(x) (x)
105# else
106# error "Unknown endianess"
107# endif
108
109# define __ENDIANESS_HANDLER__
110#endif