-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnginx-0004-ngx_files-implement-ngx_open_tempfile-in-utf8-encodi.patch
88 lines (77 loc) · 3.15 KB
/
nginx-0004-ngx_files-implement-ngx_open_tempfile-in-utf8-encodi.patch
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
From 34f9aca0bdd33867ee55b736d78006460310a9ed Mon Sep 17 00:00:00 2001
From: myfreeer <[email protected]>
Date: Tue, 5 Nov 2019 19:54:45 +0800
Subject: [PATCH 1/3] ngx_files: implement ngx_open_tempfile in utf8 encoding
---
src/os/win32/ngx_files.c | 35 ++++++++++++++++++++++++++++++++++-
src/os/win32/ngx_files.h | 11 ++---------
2 files changed, 36 insertions(+), 10 deletions(-)
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index fc69e6d..0ed27bb 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -15,6 +15,39 @@ static ngx_int_t ngx_win32_check_filename(u_char *name, u_short *u,
size_t len);
static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len);
+ngx_fd_t
+ngx_open_tempfile(u_char *name, ngx_uint_t persistent, ngx_uint_t access)
+{
+
+ size_t len;
+ u_short *u;
+ ngx_fd_t fd;
+ ngx_err_t err;
+ u_short utf16[NGX_UTF16_BUFLEN];
+
+ len = NGX_UTF16_BUFLEN;
+ u = ngx_utf8_to_utf16(utf16, name, &len);
+
+ if (u == NULL) {
+ return INVALID_HANDLE_VALUE;
+ }
+
+ fd = CreateFileW(u, GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ NULL,
+ CREATE_NEW,
+ persistent ? 0 :
+ FILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE,
+ NULL);
+
+ if (u != utf16) {
+ err = ngx_errno;
+ ngx_free(u);
+ ngx_set_errno(err);
+ }
+
+ return fd;
+}
/* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */
@@ -494,7 +527,7 @@ ngx_create_file_mapping(ngx_file_mapping_t *fm)
goto failed;
}
- fm->handle = CreateFileMapping(fm->fd, NULL, PAGE_READWRITE,
+ fm->handle = CreateFileMappingW(fm->fd, NULL, PAGE_READWRITE,
(u_long) ((off_t) fm->size >> 32),
(u_long) ((off_t) fm->size & 0xffffffff),
NULL);
diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h
index 441a9a1..6a6aa25 100644
--- a/src/os/win32/ngx_files.h
+++ b/src/os/win32/ngx_files.h
@@ -88,15 +88,8 @@ ngx_fd_t ngx_open_file(u_char *name, u_long mode, u_long create, u_long access);
#define NGX_FILE_OWNER_ACCESS 0
-#define ngx_open_tempfile(name, persistent, access) \
- CreateFile((const char *) name, \
- GENERIC_READ|GENERIC_WRITE, \
- FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, \
- NULL, \
- CREATE_NEW, \
- persistent ? 0: \
- FILE_ATTRIBUTE_TEMPORARY|FILE_FLAG_DELETE_ON_CLOSE, \
- NULL);
+ngx_fd_t ngx_open_tempfile(u_char *name, ngx_uint_t persistent,
+ ngx_uint_t access);
#define ngx_open_tempfile_n "CreateFile()"
--
2.23.0