Changed: #1249 Endianness problems while access to disk or memory

This commit is contained in:
kervala 2011-02-01 18:56:55 +01:00
parent 8e1a1acb5d
commit d7e8b51c80
2 changed files with 27 additions and 4 deletions

View file

@ -35,13 +35,19 @@ class IStream;
//------------------ DDS STUFFS -------------------- //------------------ DDS STUFFS --------------------
#ifndef NL_MAKEFOURCC #ifndef NL_MAKEFOURCC
#ifdef NL_LITTLE_ENDIAN
#define NL_MAKEFOURCC(ch0, ch1, ch2, ch3) \ #define NL_MAKEFOURCC(ch0, ch1, ch2, ch3) \
((uint32)(uint8)(ch0) | ((uint32)(uint8)(ch1) << 8) | \ ((uint32)(uint8)(ch0) | ((uint32)(uint8)(ch1) << 8) | \
((uint32)(uint8)(ch2) << 16) | ((uint32)(uint8)(ch3) << 24 )) ((uint32)(uint8)(ch2) << 16) | ((uint32)(uint8)(ch3) << 24 ))
#else
#define NL_MAKEFOURCC(ch0, ch1, ch2, ch3) \
((uint32)(uint8)(ch3) | ((uint32)(uint8)(ch2) << 8) | \
((uint32)(uint8)(ch1) << 16) | ((uint32)(uint8)(ch0) << 24 ))
#endif
#endif #endif
const uint32 DDS_HEADER = NL_MAKEFOURCC('D', 'D', 'S', ' '); const uint32 DDS_HEADER = NL_MAKEFOURCC('D', 'D', 'S', ' ');
const uint32 DXT_HEADER = NL_MAKEFOURCC('D','X', 'T', '\0'); const uint32 DXT_HEADER = NL_MAKEFOURCC('D', 'X', 'T', '\0');
const uint32 PNG_HEADER = NL_MAKEFOURCC(0x89, 'P', 'N', 'G'); const uint32 PNG_HEADER = NL_MAKEFOURCC(0x89, 'P', 'N', 'G');
const uint32 JPG_HEADER = NL_MAKEFOURCC(0xff, 0xd8, 0xff, 0xe0); const uint32 JPG_HEADER = NL_MAKEFOURCC(0xff, 0xd8, 0xff, 0xe0);

View file

@ -157,6 +157,10 @@ static void markBNPFile(std::string &path)
return; return;
} }
#ifdef NL_BIG_ENDIAN
NLMISC_BSWAP32(nOffsetFromBegining);
#endif
if (nlfseek64 (f, nOffsetFromBegining, SEEK_SET) != 0) if (nlfseek64 (f, nOffsetFromBegining, SEEK_SET) != 0)
{ {
fclose (f); fclose (f);
@ -170,6 +174,11 @@ static void markBNPFile(std::string &path)
fclose (f); fclose (f);
return; return;
} }
#ifdef NL_BIG_ENDIAN
NLMISC_BSWAP32(nNbFile);
#endif
for (uint32 i = 0; i < nNbFile; ++i) for (uint32 i = 0; i < nNbFile; ++i)
{ {
char FileName[MAX_PATH]; char FileName[MAX_PATH];
@ -223,12 +232,20 @@ static void markBNPFile(std::string &path)
return; return;
} }
#ifdef NL_BIG_ENDIAN
NLMISC_BSWAP32(nFileSize2);
#endif
uint32 nFilePos; uint32 nFilePos;
if (fread (&nFilePos, sizeof(uint32), 1, f) != 1) if (fread (&nFilePos, sizeof(uint32), 1, f) != 1)
{ {
fclose (f); fclose (f);
return; return;
} }
#ifdef NL_BIG_ENDIAN
NLMISC_BSWAP32(nFilePos);
#endif
} }
fclose (f); fclose (f);