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