diff options
author | irungentoo_trip <irungentoo@gmail.com> | 2014-10-24 18:04:27 -0700 |
---|---|---|
committer | irungentoo_trip <irungentoo@gmail.com> | 2014-10-24 18:04:27 -0700 |
commit | f73ad4ab05aaf35cd720dffbdc47c28d35d609e1 (patch) | |
tree | 6a8b49d1469ce4a341b9fca940dcf615568d7438 /toxcore | |
parent | 31c17856b8ba6c286cb86a2f7284bf4430eea01d (diff) |
Portability saving fixes for big endian systems.
Saves should now be portable from big endian to little endian systems
though I need someone to actually test it to be sure I didn't mess up.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 5 | ||||
-rw-r--r-- | toxcore/util.c | 9 | ||||
-rw-r--r-- | toxcore/util.h | 5 |
3 files changed, 16 insertions, 3 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 4841cbd9..eaf87179 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -2648,10 +2648,9 @@ uint32_t messenger_size(const Messenger *m) | |||
2648 | 2648 | ||
2649 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) | 2649 | static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type) |
2650 | { | 2650 | { |
2651 | memcpy(data, &len, sizeof(uint32_t)); | 2651 | host_to_lendian32(data, len); |
2652 | data += sizeof(uint32_t); | 2652 | data += sizeof(uint32_t); |
2653 | uint32_t temp = (MESSENGER_STATE_COOKIE_TYPE << 16) | type; | 2653 | host_to_lendian32(data, (host_tolendian16(MESSENGER_STATE_COOKIE_TYPE) << 16) | host_tolendian16(type)); |
2654 | memcpy(data, &temp, sizeof(uint32_t)); | ||
2655 | data += sizeof(uint32_t); | 2654 | data += sizeof(uint32_t); |
2656 | return data; | 2655 | return data; |
2657 | } | 2656 | } |
diff --git a/toxcore/util.c b/toxcore/util.c index 23e19290..3d444b07 100644 --- a/toxcore/util.c +++ b/toxcore/util.c | |||
@@ -93,6 +93,15 @@ uint16_t lendian_to_host16(uint16_t lendian) | |||
93 | #endif | 93 | #endif |
94 | } | 94 | } |
95 | 95 | ||
96 | void host_to_lendian32(uint8_t *dest, uint32_t num) | ||
97 | { | ||
98 | #ifdef WORDS_BIGENDIAN | ||
99 | num = ((num << 8) & 0xFF00FF00 ) | ((num >> 8) & 0xFF00FF ); | ||
100 | num = (num << 16) | (num >> 16); | ||
101 | #endif | ||
102 | memcpy(dest, &num, sizeof(uint32_t)); | ||
103 | } | ||
104 | |||
96 | void lendian_to_host32(uint32_t *dest, const uint8_t *lendian) | 105 | void lendian_to_host32(uint32_t *dest, const uint8_t *lendian) |
97 | { | 106 | { |
98 | uint32_t d; | 107 | uint32_t d; |
diff --git a/toxcore/util.h b/toxcore/util.h index 7992a985..e90eee0f 100644 --- a/toxcore/util.h +++ b/toxcore/util.h | |||
@@ -42,6 +42,11 @@ uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_I | |||
42 | void host_to_net(uint8_t *num, uint16_t numbytes); | 42 | void host_to_net(uint8_t *num, uint16_t numbytes); |
43 | #define net_to_host(x, y) host_to_net(x, y) | 43 | #define net_to_host(x, y) host_to_net(x, y) |
44 | 44 | ||
45 | uint16_t lendian_to_host16(uint16_t lendian); | ||
46 | #define host_tolendian16(x) lendian_to_host16(x) | ||
47 | |||
48 | void host_to_lendian32(uint8_t *dest, uint32_t num); | ||
49 | |||
45 | /* state load/save */ | 50 | /* state load/save */ |
46 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); | 51 | typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type); |
47 | int load_state(load_state_callback_func load_state_callback, void *outer, | 52 | int load_state(load_state_callback_func load_state_callback, void *outer, |