uwp-createfile2.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. diff --git a/src/share/win_utf8_io/win_utf8_io.c b/src/share/win_utf8_io/win_utf8_io.c
  2. index af6d0f4..6a6de15 100644
  3. --- a/src/share/win_utf8_io/win_utf8_io.c
  4. +++ b/src/share/win_utf8_io/win_utf8_io.c
  5. @@ -160,6 +160,27 @@ int get_utf8_argv(int *argc, char ***argv)
  6. /* similar to CreateFileW but accepts UTF-8 encoded lpFileName */
  7. HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
  8. {
  9. +#if defined (WINAPI_FAMILY_PARTITION) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
  10. + HANDLE handle = INVALID_HANDLE_VALUE;
  11. +
  12. + if (!flac_internal_get_utf8_filenames())
  13. + return handle;
  14. +
  15. + wchar_t *wname;
  16. +
  17. + if ((wname = wchar_from_utf8(lpFileName)) != NULL)
  18. + {
  19. + CREATEFILE2_EXTENDED_PARAMETERS cfParams = {0};
  20. + cfParams.dwSize = sizeof(CREATEFILE2_EXTENDED_PARAMETERS);
  21. + cfParams.dwFileAttributes = dwFlagsAndAttributes & FILE_ATTRIBUTE_NORMAL;
  22. + cfParams.lpSecurityAttributes = lpSecurityAttributes;
  23. + cfParams.hTemplateFile = hTemplateFile;
  24. + handle = CreateFile2(wname, dwDesiredAccess, dwShareMode, dwCreationDisposition, &cfParams);
  25. + free(wname);
  26. + }
  27. +
  28. + return handle;
  29. +#else
  30. wchar_t *wname;
  31. HANDLE handle = INVALID_HANDLE_VALUE;
  32. @@ -180,6 +201,7 @@ HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWO
  33. }
  34. return handle;
  35. +#endif
  36. }
  37. /* return number of characters in the UTF-8 string */