mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
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.
This commit is contained in:
parent
31c17856b8
commit
f73ad4ab05
|
@ -2648,10 +2648,9 @@ uint32_t messenger_size(const Messenger *m)
|
||||||
|
|
||||||
static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
|
static uint8_t *z_state_save_subheader(uint8_t *data, uint32_t len, uint16_t type)
|
||||||
{
|
{
|
||||||
memcpy(data, &len, sizeof(uint32_t));
|
host_to_lendian32(data, len);
|
||||||
data += sizeof(uint32_t);
|
data += sizeof(uint32_t);
|
||||||
uint32_t temp = (MESSENGER_STATE_COOKIE_TYPE << 16) | type;
|
host_to_lendian32(data, (host_tolendian16(MESSENGER_STATE_COOKIE_TYPE) << 16) | host_tolendian16(type));
|
||||||
memcpy(data, &temp, sizeof(uint32_t));
|
|
||||||
data += sizeof(uint32_t);
|
data += sizeof(uint32_t);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,15 @@ uint16_t lendian_to_host16(uint16_t lendian)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void host_to_lendian32(uint8_t *dest, uint32_t num)
|
||||||
|
{
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
num = ((num << 8) & 0xFF00FF00 ) | ((num >> 8) & 0xFF00FF );
|
||||||
|
num = (num << 16) | (num >> 16);
|
||||||
|
#endif
|
||||||
|
memcpy(dest, &num, sizeof(uint32_t));
|
||||||
|
}
|
||||||
|
|
||||||
void lendian_to_host32(uint32_t *dest, const uint8_t *lendian)
|
void lendian_to_host32(uint32_t *dest, const uint8_t *lendian)
|
||||||
{
|
{
|
||||||
uint32_t d;
|
uint32_t d;
|
||||||
|
|
|
@ -42,6 +42,11 @@ uint32_t id_copy(uint8_t *dest, const uint8_t *src); /* return value is CLIENT_I
|
||||||
void host_to_net(uint8_t *num, uint16_t numbytes);
|
void host_to_net(uint8_t *num, uint16_t numbytes);
|
||||||
#define net_to_host(x, y) host_to_net(x, y)
|
#define net_to_host(x, y) host_to_net(x, y)
|
||||||
|
|
||||||
|
uint16_t lendian_to_host16(uint16_t lendian);
|
||||||
|
#define host_tolendian16(x) lendian_to_host16(x)
|
||||||
|
|
||||||
|
void host_to_lendian32(uint8_t *dest, uint32_t num);
|
||||||
|
|
||||||
/* state load/save */
|
/* state load/save */
|
||||||
typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type);
|
typedef int (*load_state_callback_func)(void *outer, const uint8_t *data, uint32_t len, uint16_t type);
|
||||||
int load_state(load_state_callback_func load_state_callback, void *outer,
|
int load_state(load_state_callback_func load_state_callback, void *outer,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user