summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2011-09-14 02:26:51 +0200
committerGravatar Martin Szulecki2012-03-19 01:43:21 +0100
commit294cf69b256419e407b1eac04634752412ee7756 (patch)
treeaad873d07fca6e69547aa2609a645531fab44ddd
parentabf7eaa91e2ece0f461c71d3dcc0b2900c199209 (diff)
downloadlibimobiledevice-294cf69b256419e407b1eac04634752412ee7756.tar.gz
libimobiledevice-294cf69b256419e407b1eac04634752412ee7756.tar.bz2
New file for be*/le* macros plus check for endian.h presence
-rw-r--r--configure.ac18
-rw-r--r--include/endianness.h66
-rw-r--r--src/afc.c1
-rw-r--r--src/afc.h1
-rw-r--r--src/property_list_service.c1
-rw-r--r--tools/idevicesyslog.c1
6 files changed, 80 insertions, 8 deletions
diff --git a/configure.ac b/configure.ac
index 1bb33fa..feb5d11 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,17 +63,19 @@ if test "x$have_vasprintf" = "xyes"; then
AC_DEFINE(HAVE_VASPRINTF,1,[define if vasprintf is available])
fi
-AC_DEFINE(LITTLE_ENDIAN,0,[little endian])
-AC_DEFINE(BIG_ENDIAN,1,[big endian])
-AC_C_BIGENDIAN([ac_cv_c_bigendian="yes"], [ac_cv_c_bigendian="no"], [], [])
-if test "x$ac_cv_c_bigendian" = "xyes"; then
- AC_DEFINE(BYTE_ORDER,1,[big endian byte order])
-else
- AC_DEFINE(BYTE_ORDER,0,[little endian byte order])
+AC_CHECK_HEADER(endian.h, [ac_cv_have_endian_h="yes"], [ac_cv_have_endian_h="no"])
+if test "x$ac_cv_have_endian" = "xno"; then
+ AC_DEFINE(__LITTLE_ENDIAN,1234,[little endian])
+ AC_DEFINE(__BIG_ENDIAN,4321,[big endian])
+ AC_C_BIGENDIAN([ac_cv_c_bigendian="yes"], [ac_cv_c_bigendian="no"], [], [])
+ if test "x$ac_cv_c_bigendian" = "xyes"; then
+ AC_DEFINE(__BYTE_ORDER,4321,[big endian byte order])
+ else
+ AC_DEFINE(__BYTE_ORDER,1234,[little endian byte order])
+ fi
fi
-
AC_ARG_WITH([swig],
[AS_HELP_STRING([--without-swig],
[build Python bindings using swig (default is yes)])],
diff --git a/include/endianness.h b/include/endianness.h
new file mode 100644
index 0000000..a34cbf4
--- /dev/null
+++ b/include/endianness.h
@@ -0,0 +1,66 @@
+#ifndef ENDIANNESS_H
+#define ENDIANNESS_H
+
+#ifndef be16toh
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define be16toh(x) (x)
+#else
+#define be16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
+#endif
+#endif
+
+#ifndef __bswap_32
+#define __bswap_32(x) ((((x) & 0xFF000000) >> 24) \
+ | (((x) & 0x00FF0000) >> 8) \
+ | (((x) & 0x0000FF00) << 8) \
+ | (((x) & 0x000000FF) << 24))
+#endif
+
+#ifndef be32toh
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define be32toh(x) (x)
+#else
+#define be32toh(x) __bswap_32(x)
+#endif
+#endif
+
+#ifndef htobe32
+#define htobe32 be32toh
+#endif
+
+#ifndef __bswap_64
+#define __bswap_64(x) ((((x) & 0xFF00000000000000ull) >> 56) \
+ | (((x) & 0x00FF000000000000ull) >> 40) \
+ | (((x) & 0x0000FF0000000000ull) >> 24) \
+ | (((x) & 0x000000FF00000000ull) >> 8) \
+ | (((x) & 0x00000000FF000000ull) << 8) \
+ | (((x) & 0x0000000000FF0000ull) << 24) \
+ | (((x) & 0x000000000000FF00ull) << 40) \
+ | (((x) & 0x00000000000000FFull) << 56))
+#endif
+
+#ifndef htobe64
+#if __BYTE_ORDER == __BIG_ENDIAN
+#define htobe64(x) (x)
+#else
+#define htobe64(x) __bswap_64(x)
+#endif
+#endif
+
+#ifndef be64toh
+#define be64toh htobe64
+#endif
+
+#ifndef le64toh
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define le64toh(x) (x)
+#else
+#define le64toh(x) __bswap_64(x)
+#endif
+#endif
+
+#ifndef htole64
+#define htole64 le64toh
+#endif
+
+#endif /* ENDIANNESS_H */
diff --git a/src/afc.c b/src/afc.c
index 5ae9e38..f9c7dfa 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -30,6 +30,7 @@
#include "afc.h"
#include "idevice.h"
#include "debug.h"
+#include "endianness.h"
/** The maximum size an AFC data packet can be */
static const int MAXIMUM_PACKET_SIZE = (2 << 15);
diff --git a/src/afc.h b/src/afc.h
index 731746a..87a2fd6 100644
--- a/src/afc.h
+++ b/src/afc.h
@@ -27,6 +27,7 @@
#endif
#include "libimobiledevice/afc.h"
+#include "endianness.h"
#define AFC_MAGIC "CFA6LPAA"
#define AFC_MAGIC_LEN (8)
diff --git a/src/property_list_service.c b/src/property_list_service.c
index 0df04c7..2a15be5 100644
--- a/src/property_list_service.c
+++ b/src/property_list_service.c
@@ -27,6 +27,7 @@
#include "property_list_service.h"
#include "idevice.h"
#include "debug.h"
+#include "endianness.h"
/**
* Convert an idevice_error_t value to an property_list_service_error_t value.
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index 05e614f..d306bfc 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -27,6 +27,7 @@
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>
+#include <endianness.h>
static int quit_flag = 0;