Skip to content

Commit

Permalink
Fixed compile error on big endian systems
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Jun 29, 2016
1 parent 08aef33 commit aa75668
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/common/FileIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void BinaryFile::write_u8(uint8_t value)
void BinaryFile::write_i16(int16_t value)
{
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
int32_t tmp = value;
int16_t tmp = value;

((char*)&out)[0] = ((char*)&tmp)[1];
((char*)&out)[1] = ((char*)&tmp)[0];
((char*)&value)[0] = ((char*)&tmp)[1];
((char*)&value)[1] = ((char*)&tmp)[0];
#endif

fwrite_or_exception(&value, sizeof(int16_t), 1);
Expand All @@ -68,10 +68,10 @@ void BinaryFile::write_i32(int32_t value)
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
int32_t tmp = value;

((char*)&out)[0] = ((char*)&tmp)[3];
((char*)&out)[1] = ((char*)&tmp)[2];
((char*)&out)[2] = ((char*)&tmp)[1];
((char*)&out)[3] = ((char*)&tmp)[0];
((char*)&value)[0] = ((char*)&tmp)[3];
((char*)&value)[1] = ((char*)&tmp)[2];
((char*)&value)[2] = ((char*)&tmp)[1];
((char*)&value)[3] = ((char*)&tmp)[0];
#endif

fwrite_or_exception(&value, sizeof(int32_t), 1);
Expand All @@ -85,12 +85,12 @@ void BinaryFile::write_bool(bool value)
void BinaryFile::write_float(float value)
{
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
float tmp = out;
float tmp = value;

((char*)&out)[0] = ((char*)&tmp)[3];
((char*)&out)[1] = ((char*)&tmp)[2];
((char*)&out)[2] = ((char*)&tmp)[1];
((char*)&out)[3] = ((char*)&tmp)[0];
((char*)&value)[0] = ((char*)&tmp)[3];
((char*)&value)[1] = ((char*)&tmp)[2];
((char*)&value)[2] = ((char*)&tmp)[1];
((char*)&value)[3] = ((char*)&tmp)[0];
#endif

fwrite_or_exception(&value, sizeof(float), 1);
Expand Down Expand Up @@ -154,7 +154,7 @@ int16_t BinaryFile::read_i16()
fread_or_exception(&in, sizeof(int16_t), 1);

#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
int32_t tmp = in;
int16_t tmp = in;

((char*)&in)[0] = ((char*)&tmp)[1];
((char*)&in)[1] = ((char*)&tmp)[0];
Expand All @@ -172,7 +172,7 @@ void BinaryFile::read_i16_array(int16_t* target, size_t size)
for (unsigned int i = 0; i < size; i++) {
fread_or_exception(&target[i], sizeof(int16_t), 1);

int tmp = target[i];
int16_t tmp = target[i];

((char*)&target[i])[0] = ((char*)&tmp)[1];
((char*)&target[i])[1] = ((char*)&tmp)[0];
Expand Down Expand Up @@ -208,7 +208,7 @@ void BinaryFile::read_i32_array(int32_t* target, size_t size)
for (unsigned int i = 0; i < size; i++) {
fread_or_exception(&target[i], sizeof(int32_t), 1);

int tmp = target[i];
int32_t tmp = target[i];

((char*)&target[i])[0] = ((char*)&tmp)[3];
((char*)&target[i])[1] = ((char*)&tmp)[2];
Expand Down

0 comments on commit aa75668

Please sign in to comment.