uwp_fixes.diff 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. diff --git a/thirdparty/libwebsockets/plat/lws-plat-win.c b/thirdparty/libwebsockets/plat/lws-plat-win.c
  2. index bd513b494..1850b6425 100644
  3. --- a/thirdparty/libwebsockets/plat/lws-plat-win.c
  4. +++ b/thirdparty/libwebsockets/plat/lws-plat-win.c
  5. @@ -641,9 +641,20 @@ _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
  6. HANDLE ret;
  7. WCHAR buf[MAX_PATH];
  8. lws_fop_fd_t fop_fd;
  9. - LARGE_INTEGER llFileSize = {0};
  10. + FILE_STANDARD_INFO fInfo = {0};
  11. MultiByteToWideChar(CP_UTF8, 0, filename, -1, buf, LWS_ARRAY_SIZE(buf));
  12. +
  13. +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0602 // Windows 8 (minimum when UWP_ENABLED, but can be used in Windows builds)
  14. + CREATEFILE2_EXTENDED_PARAMETERS extParams = {0};
  15. + extParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
  16. +
  17. + if (((*flags) & 7) == _O_RDONLY) {
  18. + ret = CreateFile2(buf, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, &extParams);
  19. + } else {
  20. + ret = CreateFile2(buf, GENERIC_WRITE, 0, CREATE_ALWAYS, &extParams);
  21. + }
  22. +#else
  23. if (((*flags) & 7) == _O_RDONLY) {
  24. ret = CreateFileW(buf, GENERIC_READ, FILE_SHARE_READ,
  25. NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  26. @@ -651,6 +662,7 @@ _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
  27. ret = CreateFileW(buf, GENERIC_WRITE, 0, NULL,
  28. CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  29. }
  30. +#endif
  31. if (ret == LWS_INVALID_FILE)
  32. goto bail;
  33. @@ -663,9 +675,9 @@ _lws_plat_file_open(const struct lws_plat_file_ops *fops, const char *filename,
  34. fop_fd->fd = ret;
  35. fop_fd->filesystem_priv = NULL; /* we don't use it */
  36. fop_fd->flags = *flags;
  37. - fop_fd->len = GetFileSize(ret, NULL);
  38. - if(GetFileSizeEx(ret, &llFileSize))
  39. - fop_fd->len = llFileSize.QuadPart;
  40. + fop_fd->len = 0;
  41. + if(GetFileInformationByHandleEx(ret, FileStandardInfo, &fInfo, sizeof(fInfo)))
  42. + fop_fd->len = fInfo.EndOfFile.QuadPart;
  43. fop_fd->pos = 0;