mojoshader_preprocessor.c
changeset 861 760e1457ffc6
parent 858 d51537335896
child 864 aa3bec973a21
equal deleted inserted replaced
860:0346f9445597 861:760e1457ffc6
   201                                      unsigned int *outbytes,
   201                                      unsigned int *outbytes,
   202                                      MOJOSHADER_malloc m, MOJOSHADER_free f,
   202                                      MOJOSHADER_malloc m, MOJOSHADER_free f,
   203                                      void *d)
   203                                      void *d)
   204 {
   204 {
   205 #ifdef _MSC_VER
   205 #ifdef _MSC_VER
   206 #error Write me.
   206 	WCHAR widePath[MAX_PATH];
       
   207 	if (!MultiByteToWideChar( CP_UTF8, 0, fname, -1, widePath, MAX_PATH ))
       
   208 		return 0;
       
   209 	HANDLE fileHandle = CreateFileW (widePath, FILE_GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, NULL, NULL );
       
   210 	if (fileHandle == INVALID_HANDLE_VALUE)
       
   211 		return 0;
       
   212 	DWORD fileSize = GetFileSize (fileHandle, NULL);
       
   213 	if (fileSize == INVALID_FILE_SIZE)
       
   214 	{
       
   215 		CloseHandle (fileHandle);
       
   216 		return 0;
       
   217 	}
       
   218 	char *data = (char *) m(fileSize, d);
       
   219 	if (data == NULL)
       
   220 	{
       
   221 		CloseHandle (fileHandle);
       
   222 		return 0;
       
   223 	}
       
   224 	DWORD readLength = 0;
       
   225 	if (!ReadFile( fileHandle, data, fileSize, &readLength, NULL))
       
   226 	{
       
   227 		CloseHandle (fileHandle);
       
   228 		f(data, d);
       
   229 		return 0;
       
   230 	}
       
   231 	CloseHandle (fileHandle);
       
   232 	if (readLength != fileSize)
       
   233 	{
       
   234 		f(data, d);
       
   235 		return 0;
       
   236 	}
       
   237 	*outdata = data;
       
   238 	*outbytes = fileSize;
       
   239 	return 1;
       
   240 	
   207 #else
   241 #else
   208     struct stat statbuf;
   242     struct stat statbuf;
   209     if (stat(fname, &statbuf) == -1)
   243     if (stat(fname, &statbuf) == -1)
   210         return 0;
   244         return 0;
   211     char *data = (char *) m(statbuf.st_size, d);
   245     char *data = (char *) m(statbuf.st_size, d);