diff options
Diffstat (limited to 'src/bplist.c')
| -rw-r--r-- | src/bplist.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/bplist.c b/src/bplist.c index bb3465b..6a9d972 100644 --- a/src/bplist.c +++ b/src/bplist.c | |||
| @@ -19,6 +19,9 @@ | |||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #ifdef HAVE_CONFIG_H | ||
| 23 | #include <config.h> | ||
| 24 | #endif | ||
| 22 | 25 | ||
| 23 | #include <stdlib.h> | 26 | #include <stdlib.h> |
| 24 | #include <stdio.h> | 27 | #include <stdio.h> |
| @@ -73,7 +76,7 @@ enum | |||
| 73 | 76 | ||
| 74 | static void float_byte_convert(uint8_t * address, size_t size) | 77 | static void float_byte_convert(uint8_t * address, size_t size) |
| 75 | { | 78 | { |
| 76 | #if (PLIST_BYTE_ORDER == PLIST_LITTLE_ENDIAN \ | 79 | #if (defined(__LITTLE_ENDIAN__) \ |
| 77 | && !defined(__FLOAT_WORD_ORDER__)) \ | 80 | && !defined(__FLOAT_WORD_ORDER__)) \ |
| 78 | || (defined(__FLOAT_WORD_ORDER__) \ | 81 | || (defined(__FLOAT_WORD_ORDER__) \ |
| 79 | && __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) | 82 | && __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) |
| @@ -110,7 +113,7 @@ union plist_uint_ptr | |||
| 110 | 113 | ||
| 111 | static void byte_convert(uint8_t * address, size_t size) | 114 | static void byte_convert(uint8_t * address, size_t size) |
| 112 | { | 115 | { |
| 113 | #if PLIST_BYTE_ORDER == PLIST_LITTLE_ENDIAN | 116 | #ifdef __LITTLE_ENDIAN__ |
| 114 | uint8_t i = 0, j = 0; | 117 | uint8_t i = 0, j = 0; |
| 115 | uint8_t tmp = 0; | 118 | uint8_t tmp = 0; |
| 116 | 119 | ||
| @@ -138,7 +141,7 @@ static uint32_t uint24_from_be(union plist_uint_ptr buf) | |||
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | #ifndef be16toh | 143 | #ifndef be16toh |
| 141 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 144 | #ifdef __BIG_ENDIAN__ |
| 142 | #define be16toh(x) (x) | 145 | #define be16toh(x) (x) |
| 143 | #else | 146 | #else |
| 144 | #define be16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) | 147 | #define be16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8)) |
| @@ -146,7 +149,7 @@ static uint32_t uint24_from_be(union plist_uint_ptr buf) | |||
| 146 | #endif | 149 | #endif |
| 147 | 150 | ||
| 148 | #ifndef be32toh | 151 | #ifndef be32toh |
| 149 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 152 | #ifdef __BIG_ENDIAN__ |
| 150 | #define be32toh(x) (x) | 153 | #define be32toh(x) (x) |
| 151 | #else | 154 | #else |
| 152 | #define be32toh(x) ((((x) & 0xFF000000) >> 24) \ | 155 | #define be32toh(x) ((((x) & 0xFF000000) >> 24) \ |
| @@ -157,7 +160,7 @@ static uint32_t uint24_from_be(union plist_uint_ptr buf) | |||
| 157 | #endif | 160 | #endif |
| 158 | 161 | ||
| 159 | #ifndef be64toh | 162 | #ifndef be64toh |
| 160 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 163 | #ifdef __BIG_ENDIAN__ |
| 161 | #define be64toh(x) (x) | 164 | #define be64toh(x) (x) |
| 162 | #else | 165 | #else |
| 163 | #define be64toh(x) ((((x) & 0xFF00000000000000ull) >> 56) \ | 166 | #define be64toh(x) ((((x) & 0xFF00000000000000ull) >> 56) \ |
| @@ -827,7 +830,7 @@ static void write_int(bytearray_t * bplist, uint64_t val) | |||
| 827 | if (size == 3) | 830 | if (size == 3) |
| 828 | size++; | 831 | size++; |
| 829 | 832 | ||
| 830 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 833 | #ifdef __BIG_ENDIAN__ |
| 831 | val = val << ((sizeof(uint64_t) - size) * 8); | 834 | val = val << ((sizeof(uint64_t) - size) * 8); |
| 832 | #endif | 835 | #endif |
| 833 | 836 | ||
| @@ -950,7 +953,7 @@ static void write_array(bytearray_t * bplist, node_t* node, hashtable_t* ref_tab | |||
| 950 | for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(cur), i++) | 953 | for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(cur), i++) |
| 951 | { | 954 | { |
| 952 | idx = *(uint64_t *) (hash_table_lookup(ref_table, cur)); | 955 | idx = *(uint64_t *) (hash_table_lookup(ref_table, cur)); |
| 953 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 956 | #ifdef __BIG_ENDIAN__ |
| 954 | idx = idx << ((sizeof(uint64_t) - dict_param_size) * 8); | 957 | idx = idx << ((sizeof(uint64_t) - dict_param_size) * 8); |
| 955 | #endif | 958 | #endif |
| 956 | memcpy(buff + i * dict_param_size, &idx, dict_param_size); | 959 | memcpy(buff + i * dict_param_size, &idx, dict_param_size); |
| @@ -987,14 +990,14 @@ static void write_dict(bytearray_t * bplist, node_t* node, hashtable_t* ref_tabl | |||
| 987 | for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(node_next_sibling(cur)), i++) | 990 | for (i = 0, cur = node_first_child(node); cur && i < size; cur = node_next_sibling(node_next_sibling(cur)), i++) |
| 988 | { | 991 | { |
| 989 | idx1 = *(uint64_t *) (hash_table_lookup(ref_table, cur)); | 992 | idx1 = *(uint64_t *) (hash_table_lookup(ref_table, cur)); |
| 990 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 993 | #ifdef __BIG_ENDIAN__ |
| 991 | idx1 = idx1 << ((sizeof(uint64_t) - dict_param_size) * 8); | 994 | idx1 = idx1 << ((sizeof(uint64_t) - dict_param_size) * 8); |
| 992 | #endif | 995 | #endif |
| 993 | memcpy(buff + i * dict_param_size, &idx1, dict_param_size); | 996 | memcpy(buff + i * dict_param_size, &idx1, dict_param_size); |
| 994 | byte_convert(buff + i * dict_param_size, dict_param_size); | 997 | byte_convert(buff + i * dict_param_size, dict_param_size); |
| 995 | 998 | ||
| 996 | idx2 = *(uint64_t *) (hash_table_lookup(ref_table, cur->next)); | 999 | idx2 = *(uint64_t *) (hash_table_lookup(ref_table, cur->next)); |
| 997 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 1000 | #ifdef __BIG_ENDIAN__ |
| 998 | idx2 = idx2 << ((sizeof(uint64_t) - dict_param_size) * 8); | 1001 | idx2 = idx2 << ((sizeof(uint64_t) - dict_param_size) * 8); |
| 999 | #endif | 1002 | #endif |
| 1000 | memcpy(buff + (i + size) * dict_param_size, &idx2, dict_param_size); | 1003 | memcpy(buff + (i + size) * dict_param_size, &idx2, dict_param_size); |
| @@ -1015,7 +1018,7 @@ static void write_uid(bytearray_t * bplist, uint64_t val) | |||
| 1015 | if (size == 3) | 1018 | if (size == 3) |
| 1016 | size++; | 1019 | size++; |
| 1017 | 1020 | ||
| 1018 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 1021 | #ifdef __BIG_ENDIAN__ |
| 1019 | val = val << ((sizeof(uint64_t) - size) * 8); | 1022 | val = val << ((sizeof(uint64_t) - size) * 8); |
| 1020 | #endif | 1023 | #endif |
| 1021 | 1024 | ||
| @@ -1222,7 +1225,7 @@ PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length) | |||
| 1222 | { | 1225 | { |
| 1223 | uint8_t *offsetbuff = (uint8_t *) malloc(offset_size); | 1226 | uint8_t *offsetbuff = (uint8_t *) malloc(offset_size); |
| 1224 | 1227 | ||
| 1225 | #if PLIST_BYTE_ORDER == PLIST_BIG_ENDIAN | 1228 | #ifdef __BIG_ENDIAN__ |
| 1226 | offsets[i] = offsets[i] << ((sizeof(uint64_t) - offset_size) * 8); | 1229 | offsets[i] = offsets[i] << ((sizeof(uint64_t) - offset_size) * 8); |
| 1227 | #endif | 1230 | #endif |
| 1228 | 1231 | ||
