Win utf8 treatment for CreateFile.

Patch from Janne Hyvärinen <cse@sci.fi>.
This commit is contained in:
Erik de Castro Lopo
2013-04-21 17:53:02 +10:00
parent 92db3c951e
commit 52fab8ba7e
3 changed files with 17 additions and 3 deletions

View File

@@ -127,8 +127,8 @@ FLAC__bool grabbag__file_are_same(const char *f1, const char *f2)
BY_HANDLE_FILE_INFORMATION info1, info2;
HANDLE h1, h2;
BOOL ok = 1;
h1 = CreateFile(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
h2 = CreateFile(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
h1 = CreateFile_utf8(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
h2 = CreateFile_utf8(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE)
ok = 0;
ok &= GetFileInformationByHandle(h1, &info1);

View File

@@ -307,3 +307,16 @@ int rename_utf8(const char *oldname, const char *newname)
return ret;
}
HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
wchar_t *wname;
HANDLE handle = INVALID_HANDLE_VALUE;
if ((wname = wchar_from_utf8(lpFileName)) != NULL) {
handle = CreateFileW(wname, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
free(wname);
}
return handle;
}