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 51d09f375a
commit 84b99dbbcc
2 changed files with 27 additions and 4 deletions

View file

@ -35,9 +35,15 @@ class IStream;
//------------------ DDS STUFFS --------------------
#ifndef NL_MAKEFOURCC
#ifdef NL_LITTLE_ENDIAN
#define NL_MAKEFOURCC(ch0, ch1, ch2, ch3) \
((uint32)(uint8)(ch0) | ((uint32)(uint8)(ch1) << 8) | \
((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
const uint32 DDS_HEADER = NL_MAKEFOURCC('D', 'D', 'S', ' ');

View file

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