mojoshader_preprocessor.c
changeset 882 dd526bab5a51
parent 881 a22fe996c5a4
child 894 1847405a16c6
equal deleted inserted replaced
881:a22fe996c5a4 882:dd526bab5a51
   204                                      unsigned int *outbytes,
   204                                      unsigned int *outbytes,
   205                                      MOJOSHADER_malloc m, MOJOSHADER_free f,
   205                                      MOJOSHADER_malloc m, MOJOSHADER_free f,
   206                                      void *d)
   206                                      void *d)
   207 {
   207 {
   208 #ifdef _MSC_VER
   208 #ifdef _MSC_VER
   209 	WCHAR widePath[MAX_PATH];
   209     WCHAR wpath[MAX_PATH];
   210 	if (!MultiByteToWideChar( CP_UTF8, 0, fname, -1, widePath, MAX_PATH ))
   210     if (!MultiByteToWideChar(CP_UTF8, 0, fname, -1, wpath, MAX_PATH))
   211 		return 0;
   211         return 0;
   212 	HANDLE fileHandle = CreateFileW (widePath, FILE_GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, NULL, NULL );
   212 
   213 	if (fileHandle == INVALID_HANDLE_VALUE)
   213     const DWORD share = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
   214 		return 0;
   214     const HANDLE handle = CreateFileW(wpath, FILE_GENERIC_READ, share,
   215 	DWORD fileSize = GetFileSize (fileHandle, NULL);
   215                                       NULL, OPEN_EXISTING, NULL, NULL);
   216 	if (fileSize == INVALID_FILE_SIZE)
   216     if (handle == INVALID_HANDLE_VALUE)
   217 	{
   217         return 0;
   218 		CloseHandle (fileHandle);
   218 
   219 		return 0;
   219     const DWORD fileSize = GetFileSize(handle, NULL);
   220 	}
   220     if (fileSize == INVALID_FILE_SIZE)
   221 	char *data = (char *) m(fileSize, d);
   221     {
   222 	if (data == NULL)
   222         CloseHandle(handle);
   223 	{
   223         return 0;
   224 		CloseHandle (fileHandle);
   224     } // if
   225 		return 0;
   225 
   226 	}
   226     char *data = (char *) m(fileSize, d);
   227 	DWORD readLength = 0;
   227     if (data == NULL)
   228 	if (!ReadFile( fileHandle, data, fileSize, &readLength, NULL))
   228     {
   229 	{
   229         CloseHandle(handle);
   230 		CloseHandle (fileHandle);
   230         return 0;
   231 		f(data, d);
   231     } // if
   232 		return 0;
   232 
   233 	}
   233     DWORD readLength = 0;
   234 	CloseHandle (fileHandle);
   234     if (!ReadFile(handle, data, fileSize, &readLength, NULL))
   235 	if (readLength != fileSize)
   235     {
   236 	{
   236         CloseHandle(handle);
   237 		f(data, d);
   237         f(data, d);
   238 		return 0;
   238         return 0;
   239 	}
   239     } // if
   240 	*outdata = data;
   240 
   241 	*outbytes = fileSize;
   241     CloseHandle(handle);
   242 	return 1;
   242 
   243 	
   243     if (readLength != fileSize)
       
   244     {
       
   245         f(data, d);
       
   246         return 0;
       
   247     } // if
       
   248     *outdata = data;
       
   249     *outbytes = fileSize;
       
   250     return 1;
   244 #else
   251 #else
   245     struct stat statbuf;
   252     struct stat statbuf;
   246     if (stat(fname, &statbuf) == -1)
   253     if (stat(fname, &statbuf) == -1)
   247         return 0;
   254         return 0;
   248     char *data = (char *) m(statbuf.st_size, d);
   255     char *data = (char *) m(statbuf.st_size, d);