-
Notifications
You must be signed in to change notification settings - Fork 15
/
nginx-0003-ngx_files-implement-some-functions-in-utf8-encoding.patch
222 lines (206 loc) · 5.82 KB
/
nginx-0003-ngx_files-implement-some-functions-in-utf8-encoding.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
From 83460b316515224c0d35f69ba9cd330c22772e3e Mon Sep 17 00:00:00 2001
From: myfreeer <myfreeer@users.noreply.github.com>
Date: Mon, 4 Nov 2019 21:44:10 +0800
Subject: [PATCH] ngx_files: implement some functions in utf8 encoding
* ngx_getcwd
* ngx_create_dir
* ngx_delete_dir
* ngx_delete_file
* ngx_rename_file
nginx would initially run in non-ascii dir.
---
src/os/win32/ngx_files.c | 140 +++++++++++++++++++++++++++++++++++++++
src/os/win32/ngx_files.h | 24 +++----
2 files changed, 150 insertions(+), 14 deletions(-)
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index f2d07e1..fc69e6d 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -301,6 +301,146 @@ failed:
return rc;
}
+ngx_int_t
+ngx_getcwd(u_char *buf, ngx_int_t size)
+{
+ WCHAR wBuffer[NGX_MAX_PATH];
+ ngx_int_t ret = GetCurrentDirectoryW(NGX_MAX_PATH, wBuffer);
+ if (ret == 0) {
+ return 0;
+ }
+ return WideCharToMultiByte(CP_UTF8, 0, wBuffer, -1, (char *) buf, size, NULL, NULL);
+}
+
+ngx_int_t
+ngx_create_dir(u_char *name, ngx_int_t access)
+{
+ size_t len;
+ long rc;
+ u_short *u;
+ 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 NGX_FILE_ERROR;
+ }
+
+ rc = CreateDirectoryW((const WCHAR *)u, NULL);
+
+ if (u != utf16) {
+ err = ngx_errno;
+ ngx_free(u);
+ ngx_set_errno(err);
+ }
+
+ return rc;
+}
+
+ngx_int_t
+ngx_delete_dir(u_char *name)
+{
+ size_t len;
+ long rc;
+ u_short *u;
+ 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 NGX_FILE_ERROR;
+ }
+
+ rc = RemoveDirectoryW((const WCHAR *)u);
+
+ if (u != utf16) {
+ err = ngx_errno;
+ ngx_free(u);
+ ngx_set_errno(err);
+ }
+
+ return rc;
+}
+
+ngx_int_t
+ngx_delete_file(u_char *name)
+{
+ size_t len;
+ long rc;
+ u_short *u;
+ 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 NGX_FILE_ERROR;
+ }
+
+ rc = DeleteFileW((const WCHAR *)u);
+
+ if (u != utf16) {
+ err = ngx_errno;
+ ngx_free(u);
+ ngx_set_errno(err);
+ }
+
+ return rc;
+}
+
+ngx_int_t
+ngx_rename_file(u_char *o, u_char *n)
+{
+ size_t len1;
+ size_t len2;
+ long rc;
+ u_short *u1;
+ u_short *u2;
+ ngx_err_t err;
+ u_short utf16_1[NGX_UTF16_BUFLEN];
+ u_short utf16_2[NGX_UTF16_BUFLEN];
+
+ len1 = NGX_UTF16_BUFLEN;
+ len2 = NGX_UTF16_BUFLEN;
+
+ u1 = ngx_utf8_to_utf16(utf16_1, o, &len1);
+
+ if (u1 == NULL) {
+ return NGX_FILE_ERROR;
+ }
+
+ rc = NGX_FILE_ERROR;
+ u2 = ngx_utf8_to_utf16(utf16_2, n, &len2);
+
+ if (u2 == NULL) {
+ goto fail1;
+ }
+
+ rc = MoveFileW((const WCHAR *) u1, (const WCHAR *) u2);
+
+ if (u2 != utf16_2) {
+ err = ngx_errno;
+ ngx_free(u2);
+ ngx_set_errno(err);
+ }
+
+fail1:
+ if (u1 != utf16_1) {
+ err = ngx_errno;
+ ngx_free(u1);
+ ngx_set_errno(err);
+ }
+
+ return rc;
+}
ngx_int_t
ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s)
diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h
index 57bfe7e..441a9a1 100644
--- a/src/os/win32/ngx_files.h
+++ b/src/os/win32/ngx_files.h
@@ -120,13 +120,11 @@ ssize_t ngx_write_console(ngx_fd_t fd, void *buf, size_t size);
#define NGX_LINEFEED_SIZE 2
#define NGX_LINEFEED CRLF
+ngx_int_t ngx_delete_file(u_char *name);
+#define ngx_delete_file_n "DeleteFileW()"
-#define ngx_delete_file(name) DeleteFile((const char *) name)
-#define ngx_delete_file_n "DeleteFile()"
-
-
-#define ngx_rename_file(o, n) MoveFile((const char *) o, (const char *) n)
-#define ngx_rename_file_n "MoveFile()"
+ngx_int_t ngx_rename_file(u_char *o, u_char *n);
+#define ngx_rename_file_n "MoveFileW()"
ngx_err_t ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log);
@@ -176,8 +174,8 @@ void ngx_close_file_mapping(ngx_file_mapping_t *fm);
u_char *ngx_realpath(u_char *path, u_char *resolved);
#define ngx_realpath_n ""
-#define ngx_getcwd(buf, size) GetCurrentDirectory(size, (char *) buf)
-#define ngx_getcwd_n "GetCurrentDirectory()"
+ngx_int_t ngx_getcwd(u_char *buf, ngx_int_t size);
+#define ngx_getcwd_n "GetCurrentDirectoryW()"
#define ngx_path_separator(c) ((c) == '/' || (c) == '\\')
#define NGX_HAVE_MAX_PATH 1
@@ -195,13 +193,11 @@ ngx_int_t ngx_read_dir(ngx_dir_t *dir);
ngx_int_t ngx_close_dir(ngx_dir_t *dir);
#define ngx_close_dir_n "FindClose()"
+ngx_int_t ngx_create_dir(u_char *name, ngx_int_t access);
+#define ngx_create_dir_n "CreateDirectoryW()"
-#define ngx_create_dir(name, access) CreateDirectory((const char *) name, NULL)
-#define ngx_create_dir_n "CreateDirectory()"
-
-
-#define ngx_delete_dir(name) RemoveDirectory((const char *) name)
-#define ngx_delete_dir_n "RemoveDirectory()"
+ngx_int_t ngx_delete_dir(u_char *name);
+#define ngx_delete_dir_n "RemoveDirectoryW()"
#define ngx_dir_access(a) (a)
--
2.23.0