Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build on Windows (MinGW) #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions source/glbind_build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ glbResult glbOpenAndReadFileWithExtraData(const char* filePath, size_t* pFileSiz
{
glbResult result;
FILE* pFile;
uint64_t fileSize;
uint64_t fileSize, originalFileSize;
void* pFileData;
size_t bytesRead;
char* pFileCharData;
size_t bytesRead, readerIndex, writerIndex;

/* Safety. */
if (pFileSizeOut) *pFileSizeOut = 0;
Expand Down Expand Up @@ -166,6 +167,21 @@ glbResult glbOpenAndReadFileWithExtraData(const char* filePath, size_t* pFileSiz

fclose(pFile);

originalFileSize = fileSize;
readerIndex = 0, writerIndex = 0;
pFileCharData = (char*)pFileData; /* (void*) to (char*) cast is well-defined */
while(readerIndex < originalFileSize){ /* tinyxml2 strips CR's, so this is required for mixing with the parsed code */
if(pFileCharData[readerIndex] == '\r' && pFileCharData[readerIndex + 1] == '\n'){ /* CR followed by LF */
fileSize--;
} else{
pFileCharData[writerIndex] = pFileCharData[readerIndex];
writerIndex++;
}
readerIndex++;
}

pFileData = realloc(pFileData, (size_t)fileSize + extraBytes); /* Reduce malloc'd size if necessary */

if (pFileSizeOut) {
*pFileSizeOut = (size_t)fileSize;
}
Expand Down Expand Up @@ -217,7 +233,7 @@ glbResult glbOpenAndWriteFile(const char* filePath, const void* pData, size_t da
return GLB_INVALID_ARGS;
}

result = glbFOpen(filePath, "wb", &pFile);
result = glbFOpen(filePath, "w", &pFile); /* Windows needs CRLF */
if (result != GLB_SUCCESS) {
return GLB_FAILED_TO_OPEN_FILE;
}
Expand Down