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
63 AC_DEFINE(HAVE_VASPRINTF,1,[define if vasprintf is available]) 63 AC_DEFINE(HAVE_VASPRINTF,1,[define if vasprintf is available])
64fi 64fi
65 65
66AC_DEFINE(LITTLE_ENDIAN,0,[little endian]) 66AC_CHECK_HEADER(endian.h, [ac_cv_have_endian_h="yes"], [ac_cv_have_endian_h="no"])
67AC_DEFINE(BIG_ENDIAN,1,[big endian]) 67if test "x$ac_cv_have_endian" = "xno"; then
68AC_C_BIGENDIAN([ac_cv_c_bigendian="yes"], [ac_cv_c_bigendian="no"], [], []) 68 AC_DEFINE(__LITTLE_ENDIAN,1234,[little endian])
69if test "x$ac_cv_c_bigendian" = "xyes"; then 69 AC_DEFINE(__BIG_ENDIAN,4321,[big endian])
70 AC_DEFINE(BYTE_ORDER,1,[big endian byte order]) 70 AC_C_BIGENDIAN([ac_cv_c_bigendian="yes"], [ac_cv_c_bigendian="no"], [], [])
71else 71 if test "x$ac_cv_c_bigendian" = "xyes"; then
72 AC_DEFINE(BYTE_ORDER,0,[little endian byte order]) 72 AC_DEFINE(__BYTE_ORDER,4321,[big endian byte order])
73 else
74 AC_DEFINE(__BYTE_ORDER,1234,[little endian byte order])
75 fi
73fi 76fi
74 77
75 78
76
77AC_ARG_WITH([swig], 79AC_ARG_WITH([swig],
78 [AS_HELP_STRING([--without-swig], 80 [AS_HELP_STRING([--without-swig],
79 [build Python bindings using swig (default is yes)])], 81 [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 @@
1#ifndef ENDIANNESS_H
2#define ENDIANNESS_H
3
4#ifndef be16toh
5#if __BYTE_ORDER == __BIG_ENDIAN
6#define be16toh(x) (x)
7#else
8#define be16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
9#endif
10#endif
11
12#ifndef __bswap_32
13#define __bswap_32(x) ((((x) & 0xFF000000) >> 24) \
14 | (((x) & 0x00FF0000) >> 8) \
15 | (((x) & 0x0000FF00) << 8) \
16 | (((x) & 0x000000FF) << 24))
17#endif
18
19#ifndef be32toh
20#if __BYTE_ORDER == __BIG_ENDIAN
21#define be32toh(x) (x)
22#else
23#define be32toh(x) __bswap_32(x)
24#endif
25#endif
26
27#ifndef htobe32
28#define htobe32 be32toh
29#endif
30
31#ifndef __bswap_64
32#define __bswap_64(x) ((((x) & 0xFF00000000000000ull) >> 56) \
33 | (((x) & 0x00FF000000000000ull) >> 40) \
34 | (((x) & 0x0000FF0000000000ull) >> 24) \
35 | (((x) & 0x000000FF00000000ull) >> 8) \
36 | (((x) & 0x00000000FF000000ull) << 8) \
37 | (((x) & 0x0000000000FF0000ull) << 24) \
38 | (((x) & 0x000000000000FF00ull) << 40) \
39 | (((x) & 0x00000000000000FFull) << 56))
40#endif
41
42#ifndef htobe64
43#if __BYTE_ORDER == __BIG_ENDIAN
44#define htobe64(x) (x)
45#else
46#define htobe64(x) __bswap_64(x)
47#endif
48#endif
49
50#ifndef be64toh
51#define be64toh htobe64
52#endif
53
54#ifndef le64toh
55#if __BYTE_ORDER == __LITTLE_ENDIAN
56#define le64toh(x) (x)
57#else
58#define le64toh(x) __bswap_64(x)
59#endif
60#endif
61
62#ifndef htole64
63#define htole64 le64toh
64#endif
65
66#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 @@
30#include "afc.h" 30#include "afc.h"
31#include "idevice.h" 31#include "idevice.h"
32#include "debug.h" 32#include "debug.h"
33#include "endianness.h"
33 34
34/** The maximum size an AFC data packet can be */ 35/** The maximum size an AFC data packet can be */
35static const int MAXIMUM_PACKET_SIZE = (2 << 15); 36static 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 @@
27#endif 27#endif
28 28
29#include "libimobiledevice/afc.h" 29#include "libimobiledevice/afc.h"
30#include "endianness.h"
30 31
31#define AFC_MAGIC "CFA6LPAA" 32#define AFC_MAGIC "CFA6LPAA"
32#define AFC_MAGIC_LEN (8) 33#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 @@
27#include "property_list_service.h" 27#include "property_list_service.h"
28#include "idevice.h" 28#include "idevice.h"
29#include "debug.h" 29#include "debug.h"
30#include "endianness.h"
30 31
31/** 32/**
32 * Convert an idevice_error_t value to an property_list_service_error_t value. 33 * 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 @@
27 27
28#include <libimobiledevice/libimobiledevice.h> 28#include <libimobiledevice/libimobiledevice.h>
29#include <libimobiledevice/lockdown.h> 29#include <libimobiledevice/lockdown.h>
30#include <endianness.h>
30 31
31static int quit_flag = 0; 32static int quit_flag = 0;
32 33