summaryrefslogtreecommitdiff
path: root/navit/endianess.h
diff options
context:
space:
mode:
authorspaetz <spaetz@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-05-20 08:00:24 +0000
committerspaetz <spaetz@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-05-20 08:00:24 +0000
commita66f26537314b3d0b6fa6f2e3b9ce808a56a7e69 (patch)
treed005f405fd9d6a9606a63c729ca5d1187e4d78f9 /navit/endianess.h
parentf54fcb58d30aba0f5a6f846a7607214743a45c0c (diff)
downloadnavit-a66f26537314b3d0b6fa6f2e3b9ce808a56a7e69.tar.gz
fix trac ticket 104, by fixing the endianess byte switching headers. fix based on the bsd-licensed xorg code.
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1065 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/endianess.h')
-rw-r--r--navit/endianess.h86
1 files changed, 58 insertions, 28 deletions
diff --git a/navit/endianess.h b/navit/endianess.h
index 3764dd731..69c33a7bc 100644
--- a/navit/endianess.h
+++ b/navit/endianess.h
@@ -1,36 +1,66 @@
#ifndef __ENDIANESS_HANDLER__
-#ifndef __APPLE__
- #include <endian.h>
+ /* The following is based on xorg/xserver/GL/glx/glxbyteorder.h
+ * which is (c) IBM Corp. 2006,2007 and originally licensed under the following
+ * BSD-license. All modifications in navit are licensed under the GNU GPL as
+ * described in file "COPYRIGHT".
+ * --------------------------
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDERS, THE AUTHORS, AND/OR THEIR SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#if HAVE_BYTESWAP_H
+ /* machine dependent versions of byte swapping functions. GNU extension.*/
+ #include <byteswap.h>
+#elif defined(USE_SYS_ENDIAN_H)
+ #include <sys/endian.h>
+#elif defined(__APPLE__)
+ #include <libkern/OSByteOrder.h>
+ #define __bswap_16 OSSwapInt16
+ #define __bswap_32 OSSwapInt32
+ #define __bswap_64 OSSwapInt64
#else
- # include <machine/endian.h>
+ #define __bswap_16(value) \
+ ((((value) & 0xff) << 8) | ((value) >> 8))
+ #define __bswap_32(value) \
+ (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
+ (uint32_t)bswap_16((uint16_t)((value) >> 16)))
+ #define __bswap_64(value) \
+ (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
+ << 32) | \
+ (uint64_t)bswap_32((uint32_t)((value) >> 32)))
#endif
-/* Get machine dependent optimized versions of byte swapping functions. */
-#include <byteswap.h>
-
-#ifdef __OPTIMIZE__
-/* We can optimize calls to the conversion functions. Either nothing has
- to be done or we are using directly the byte-swapping functions which
- often can be inlined. */
-
- #if __BYTE_ORDER == __BIG_ENDIAN
- #define le16_to_cpu(x) __bswap_16 (x)
- #define le32_to_cpu(x) __bswap_32 (x)
- #define le64_to_cpu(x) __bswap_64 (x)
- #define cpu_to_le16(x) __bswap_16 (x)
- #define cpu_to_le32(x) __bswap_32 (x)
- #define cpu_to_le64(x) __bswap_64 (x)
- #else
- #if __BYTE_ORDER == __LITTLE_ENDIAN
- #define le16_to_cpu(x) (x)
- #define le32_to_cpu(x) (x)
- #define cpu_to_le16(x) (x)
- #define cpu_to_le16(x) (x)
- #else
- #error "Unknown endianess"
- #endif
- #endif
+#if __BYTE_ORDER == __BIG_ENDIAN
+ #define le16_to_cpu(x) __bswap_16 (x)
+ #define le32_to_cpu(x) __bswap_32 (x)
+ #define le64_to_cpu(x) __bswap_64 (x)
+ #define cpu_to_le16(x) __bswap_16 (x)
+ #define cpu_to_le32(x) __bswap_32 (x)
+ #define cpu_to_le64(x) __bswap_64 (x)
+#elif __BYTE_ORDER == __LITTLE_ENDIAN
+ #define le16_to_cpu(x) (x)
+ #define le32_to_cpu(x) (x)
+ #define cpu_to_le16(x) (x)
+ #define cpu_to_le16(x) (x)
+#else
+ #error "Unknown endianess"
#endif
#define __ENDIANESS_HANDLER__