Skip to content

Commit

Permalink
preprocessor open impl on MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
aras-p committed Feb 24, 2010
1 parent 33b3d11 commit ed706c5
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion mojoshader_preprocessor.c
Expand Up @@ -203,7 +203,41 @@ int MOJOSHADER_internal_include_open(MOJOSHADER_includeType inctype,
void *d)
{
#ifdef _MSC_VER
#error Write me.
WCHAR widePath[MAX_PATH];
if (!MultiByteToWideChar( CP_UTF8, 0, fname, -1, widePath, MAX_PATH ))
return 0;
HANDLE fileHandle = CreateFileW (widePath, FILE_GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, NULL, NULL );
if (fileHandle == INVALID_HANDLE_VALUE)
return 0;
DWORD fileSize = GetFileSize (fileHandle, NULL);
if (fileSize == INVALID_FILE_SIZE)
{
CloseHandle (fileHandle);
return 0;
}
char *data = (char *) m(fileSize, d);
if (data == NULL)
{
CloseHandle (fileHandle);
return 0;
}
DWORD readLength = 0;
if (!ReadFile( fileHandle, data, fileSize, &readLength, NULL))
{
CloseHandle (fileHandle);
f(data, d);
return 0;
}
CloseHandle (fileHandle);
if (readLength != fileSize)
{
f(data, d);
return 0;
}
*outdata = data;
*outbytes = fileSize;
return 1;

#else
struct stat statbuf;
if (stat(fname, &statbuf) == -1)
Expand Down

0 comments on commit ed706c5

Please sign in to comment.