Our previous include file only supplied a very limited set of
wrapper redefinitions for platforms that define __APPLE__ (i.e.
Mac OS). In particular, some needed big endian conversions were
missing, causing "symbol(s) not found" errors when linking.

Instead of patching the existing file, let's do away with it
completely and replace it by something more sophisticated.
The portable_endian.h used is in the public domain, and was
taken from https://gist.github.com/panzi/6856583

Signed-off-by: Bernhard Nortmann <bernhard.nortm...@web.de>
---
 fel.c                     |   2 +-
 include/endian_compat.h   |  36 --------------
 include/portable_endian.h | 118 ++++++++++++++++++++++++++++++++++++++++++++++
 phoenix_info.c            |   2 +-
 pio.c                     |   2 +-
 5 files changed, 121 insertions(+), 39 deletions(-)
 delete mode 100644 include/endian_compat.h
 create mode 100644 include/portable_endian.h

diff --git a/fel.c b/fel.c
index 88ca3ab..9b9144d 100644
--- a/fel.c
+++ b/fel.c
@@ -34,7 +34,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-#include "endian_compat.h"
+#include "portable_endian.h"
 #include "progress.h"
 
 static const uint16_t AW_USB_VENDOR_ID  = 0x1F3A;
diff --git a/include/endian_compat.h b/include/endian_compat.h
deleted file mode 100644
index e463a52..0000000
--- a/include/endian_compat.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2012  Eric Molitor <e...@molitor.org>
- *
- * 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, sublicense, 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 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS 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.
- */
-
-#ifndef SUNXI_ENDIAN_COMPAT_H_
-#define SUNXI_ENDIAN_COMPAT_H_
-
-#ifdef __APPLE__
-#include <CoreFoundation/CoreFoundation.h>
-#define htole32(x) CFSwapInt32HostToLittle(x)
-#define le32toh(x) CFSwapInt32LittleToHost(x)
-#define htole16(x) CFSwapInt16HostToLittle(x)
-#define le16toh(x) CFSwapInt16LittleToHost(x)
-#else
-#include <endian.h>
-#endif
-
-#endif
diff --git a/include/portable_endian.h b/include/portable_endian.h
new file mode 100644
index 0000000..2b43378
--- /dev/null
+++ b/include/portable_endian.h
@@ -0,0 +1,118 @@
+// "License": Public Domain
+// I, Mathias Panzenböck, place this file hereby into the public domain. Use 
it at your own risk for whatever you like.
+// In case there are jurisdictions that don't support putting things in the 
public domain you can also consider it to
+// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. 
This code is trivial anyway. Consider it
+// an example on how to get the endian conversion functions on different 
platforms.
+
+#ifndef PORTABLE_ENDIAN_H__
+#define PORTABLE_ENDIAN_H__
+
+#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && 
!defined(__WINDOWS__)
+
+#      define __WINDOWS__
+
+#endif
+
+#if defined(__linux__) || defined(__CYGWIN__)
+
+#      include <endian.h>
+
+#elif defined(__APPLE__)
+
+#      include <libkern/OSByteOrder.h>
+
+#      define htobe16(x) OSSwapHostToBigInt16(x)
+#      define htole16(x) OSSwapHostToLittleInt16(x)
+#      define be16toh(x) OSSwapBigToHostInt16(x)
+#      define le16toh(x) OSSwapLittleToHostInt16(x)
+
+#      define htobe32(x) OSSwapHostToBigInt32(x)
+#      define htole32(x) OSSwapHostToLittleInt32(x)
+#      define be32toh(x) OSSwapBigToHostInt32(x)
+#      define le32toh(x) OSSwapLittleToHostInt32(x)
+
+#      define htobe64(x) OSSwapHostToBigInt64(x)
+#      define htole64(x) OSSwapHostToLittleInt64(x)
+#      define be64toh(x) OSSwapBigToHostInt64(x)
+#      define le64toh(x) OSSwapLittleToHostInt64(x)
+
+#      define __BYTE_ORDER    BYTE_ORDER
+#      define __BIG_ENDIAN    BIG_ENDIAN
+#      define __LITTLE_ENDIAN LITTLE_ENDIAN
+#      define __PDP_ENDIAN    PDP_ENDIAN
+
+#elif defined(__OpenBSD__)
+
+#      include <sys/endian.h>
+
+#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
+
+#      include <sys/endian.h>
+
+#      define be16toh(x) betoh16(x)
+#      define le16toh(x) letoh16(x)
+
+#      define be32toh(x) betoh32(x)
+#      define le32toh(x) letoh32(x)
+
+#      define be64toh(x) betoh64(x)
+#      define le64toh(x) letoh64(x)
+
+#elif defined(__WINDOWS__)
+
+#      include <winsock2.h>
+#      include <sys/param.h>
+
+#      if BYTE_ORDER == LITTLE_ENDIAN
+
+#              define htobe16(x) htons(x)
+#              define htole16(x) (x)
+#              define be16toh(x) ntohs(x)
+#              define le16toh(x) (x)
+
+#              define htobe32(x) htonl(x)
+#              define htole32(x) (x)
+#              define be32toh(x) ntohl(x)
+#              define le32toh(x) (x)
+
+#              define htobe64(x) htonll(x)
+#              define htole64(x) (x)
+#              define be64toh(x) ntohll(x)
+#              define le64toh(x) (x)
+
+#      elif BYTE_ORDER == BIG_ENDIAN
+
+               /* that would be xbox 360 */
+#              define htobe16(x) (x)
+#              define htole16(x) __builtin_bswap16(x)
+#              define be16toh(x) (x)
+#              define le16toh(x) __builtin_bswap16(x)
+
+#              define htobe32(x) (x)
+#              define htole32(x) __builtin_bswap32(x)
+#              define be32toh(x) (x)
+#              define le32toh(x) __builtin_bswap32(x)
+
+#              define htobe64(x) (x)
+#              define htole64(x) __builtin_bswap64(x)
+#              define be64toh(x) (x)
+#              define le64toh(x) __builtin_bswap64(x)
+
+#      else
+
+#              error byte order not supported
+
+#      endif
+
+#      define __BYTE_ORDER    BYTE_ORDER
+#      define __BIG_ENDIAN    BIG_ENDIAN
+#      define __LITTLE_ENDIAN LITTLE_ENDIAN
+#      define __PDP_ENDIAN    PDP_ENDIAN
+
+#else
+
+#      error platform not supported
+
+#endif
+
+#endif
diff --git a/phoenix_info.c b/phoenix_info.c
index bf84cf0..0529391 100644
--- a/phoenix_info.c
+++ b/phoenix_info.c
@@ -25,7 +25,7 @@
 #include <string.h>
 #include <unistd.h>
 
-#include "endian_compat.h"
+#include "portable_endian.h"
 
 struct phoenix_ptable {
        char signature[16];             /* "PHOENIX_CARD_IMG" */
diff --git a/pio.c b/pio.c
index fc90190..a34c6c5 100644
--- a/pio.c
+++ b/pio.c
@@ -34,7 +34,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 
-#include "endian_compat.h"
+#include "portable_endian.h"
 
 #define PIO_REG_SIZE 0x228 /*0x300*/
 #define PIO_PORT_SIZE 0x24
-- 
2.4.10

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to