Move the two low-level file I/O helper to their respective single place of usage.

This commit is contained in:
Adam Reichold
2015-12-26 14:35:36 +01:00
parent e853629854
commit 0eab0ebd94
4 changed files with 53 additions and 61 deletions

View File

@@ -68,7 +68,25 @@ int munmap(void *start, size_t length)
IMFILE* fopen (const char* fname)
{
int fd = safe_open_ReadOnly(fname);
int fd = -1;
#ifdef WIN32
{
// First convert UTF8 to UTF16, then use Windows function to open the file and convert back to file descriptor.
std::unique_ptr<wchar_t, GFreeFunc> wfname (reinterpret_cast<wchar_t*>(g_utf8_to_utf16 (fname, -1, NULL, NULL, NULL)), g_free);
HANDLE hFile = CreateFileW (wfname.get (), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
fd = _open_osfhandle((intptr_t)hFile, 0);
}
}
#else
fd = ::g_open (fname, O_RDONLY);
#endif
if ( fd < 0 ) {
return 0;