[builds/windows] Try both wide and narrow `CreateFile`

Windows handles wchar_t* UTF-16 and char* ANSI (presently UTF-8)
filenames using alternative -A and -W API. We'll try them both
when opening a file. This means that you should not worry about
about conversions.

Fixes #1098 and !76.

* builds/windows/ftsystem.c (FT_Stream_Open): Call alternative
`CreateFile` in the case of failure.
This commit is contained in:
Alexei Podtelezhnikov 2021-09-17 08:31:27 -04:00
parent 6e1ef98a04
commit 0b429b609c
1 changed files with 15 additions and 3 deletions

View File

@ -214,11 +214,23 @@
file = CreateFile( (LPCTSTR)filepathname, GENERIC_READ, FILE_SHARE_READ, file = CreateFile( (LPCTSTR)filepathname, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
if ( file == INVALID_HANDLE_VALUE ) if ( file == INVALID_HANDLE_VALUE )
{
/* fall back on the alernative interface */
#ifdef UNICODE
file = CreateFileA( (LPCSTR)filepathname, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
#else
file = CreateFileW( (LPCWSTR)filepathname, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
#endif
if ( file == INVALID_HANDLE_VALUE )
{ {
FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( "FT_Stream_Open:" ));
FT_ERROR(( " could not open `%s'\n", filepathname )); FT_ERROR(( " could not open `%s'\n", filepathname ));
return FT_THROW( Cannot_Open_Resource ); return FT_THROW( Cannot_Open_Resource );
} }
}
#if defined _WIN32_WCE || defined _WIN32_WINDOWS || \ #if defined _WIN32_WCE || defined _WIN32_WINDOWS || \
(defined _WIN32_WINNT && _WIN32_WINNT <= 0x0400) (defined _WIN32_WINNT && _WIN32_WINNT <= 0x0400)