winamp/vcpkg-ports/libflac/uwp-createfile2.patch
2024-09-24 14:54:57 +02:00

41 lines
1.5 KiB
Diff

diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c
index af6d0f4..6a6de15 100644
--- a/src/share/win_utf8_io/win_utf8_io.c
+++ b/src/share/win_utf8_io/win_utf8_io.c
@@ -160,6 +160,27 @@ int get_utf8_argv(int *argc, char ***argv)
/* similar to CreateFileW but accepts UTF-8 encoded lpFileName */
HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
+#if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
+ HANDLE handle = INVALID_HANDLE_VALUE;
+
+ if (!flac_internal_get_utf8_filenames())
+ return handle;
+
+ wchar_t *wname;
+
+ if ((wname = wchar_from_utf8(lpFileName)) != NULL)
+ {
+ CREATEFILE2_EXTENDED_PARAMETERS cfParams = {0};
+ cfParams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
+ cfParams.dwFileAttributes = dwFlagsAndAttributes & FILE_ATTRIBUTE_NORMAL;
+ cfParams.lpSecurityAttributes = lpSecurityAttributes;
+ cfParams.hTemplateFile = hTemplateFile;
+ handle = CreateFile2(wname, dwDesiredAccess, dwShareMode, dwCreationDisposition, &cfParams);
+ free(wname);
+ }
+
+ return handle;
+#else
wchar_t *wname;
HANDLE handle = INVALID_HANDLE_VALUE;
@@ -180,6 +201,7 @@ HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWO
}
return handle;
+#endif
}
/* return number of characters in the UTF-8 string */