-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnginx-0005-ngx_files-implement-ngx_open_glob-and-ngx_read_glob-.patch
130 lines (107 loc) · 3.82 KB
/
nginx-0005-ngx_files-implement-ngx_open_glob-and-ngx_read_glob-.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
From 95e5e4c05f8e3d2f643fa65011c5b3527746af0b Mon Sep 17 00:00:00 2001
From: myfreeer <[email protected]>
Date: Tue, 5 Nov 2019 20:42:09 +0800
Subject: [PATCH 2/3] ngx_files: implement ngx_open_glob and ngx_read_glob in
utf8 encoding
include would work in non-ascii path on win32
---
src/os/win32/ngx_files.c | 46 +++++++++++++++++++++++++++++-----------
src/os/win32/ngx_files.h | 2 +-
2 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c
index 0ed27bb..fb413f2 100644
--- a/src/os/win32/ngx_files.c
+++ b/src/os/win32/ngx_files.c
@@ -680,11 +680,20 @@ ngx_close_dir(ngx_dir_t *dir)
ngx_int_t
ngx_open_glob(ngx_glob_t *gl)
{
+ ngx_int_t rc;
u_char *p;
size_t len;
ngx_err_t err;
+ u_short *u;
+ u_short utf16[NGX_UTF16_BUFLEN];
+
+ len = NGX_UTF16_BUFLEN;
+ u = ngx_utf8_to_utf16(utf16, gl->pattern, &len);
+ if (u == NULL) {
+ return NGX_ERROR;
+ }
- gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata);
+ gl->dir = FindFirstFileW((LPCWSTR) u, &gl->finddata);
if (gl->dir == INVALID_HANDLE_VALUE) {
@@ -694,10 +703,12 @@ ngx_open_glob(ngx_glob_t *gl)
&& gl->test)
{
gl->no_match = 1;
- return NGX_OK;
+ rc = NGX_OK;
+ goto failed;
}
- return NGX_ERROR;
+ rc = NGX_ERROR;
+ goto failed;
}
for (p = gl->pattern; *p; p++) {
@@ -706,21 +717,30 @@ ngx_open_glob(ngx_glob_t *gl)
}
}
- len = ngx_strlen(gl->finddata.cFileName);
+ len = WideCharToMultiByte(CP_UTF8, 0, gl->finddata.cFileName, -1, NULL, 0, NULL, NULL);
gl->name.len = gl->last + len;
gl->name.data = ngx_alloc(gl->name.len + 1, gl->log);
if (gl->name.data == NULL) {
- return NGX_ERROR;
+ rc = NGX_ERROR;
+ goto failed;
}
ngx_memcpy(gl->name.data, gl->pattern, gl->last);
- ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName,
- len + 1);
+ WideCharToMultiByte(CP_UTF8, 0, gl->finddata.cFileName, -1,
+ (char *) gl->name.data + gl->last, len, NULL, NULL);
+ gl->name.data[gl->name.len] = '\0';
gl->ready = 1;
+ rc = NGX_OK;
- return NGX_OK;
+failed:
+ if (u != utf16) {
+ err = ngx_errno;
+ ngx_free(u);
+ ngx_set_errno(err);
+ }
+ return rc;
}
@@ -744,9 +764,9 @@ ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name)
ngx_free(gl->name.data);
gl->name.data = NULL;
- if (FindNextFile(gl->dir, &gl->finddata) != 0) {
+ if (FindNextFileW(gl->dir, &gl->finddata) != 0) {
- len = ngx_strlen(gl->finddata.cFileName);
+ len = WideCharToMultiByte(CP_UTF8, 0, gl->finddata.cFileName, -1, NULL, 0, NULL, NULL);
gl->name.len = gl->last + len;
gl->name.data = ngx_alloc(gl->name.len + 1, gl->log);
@@ -755,8 +775,10 @@ ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name)
}
ngx_memcpy(gl->name.data, gl->pattern, gl->last);
- ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName,
- len + 1);
+
+ WideCharToMultiByte(CP_UTF8, 0, gl->finddata.cFileName, -1,
+ (char *) gl->name.data + gl->last, len, NULL, NULL);
+ gl->name.data[gl->name.len] = '\0';
*name = gl->name;
diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h
index 6a6aa25..01e64a0 100644
--- a/src/os/win32/ngx_files.h
+++ b/src/os/win32/ngx_files.h
@@ -42,7 +42,7 @@ typedef struct {
typedef struct {
HANDLE dir;
- WIN32_FIND_DATA finddata;
+ WIN32_FIND_DATAW finddata;
unsigned ready:1;
unsigned test:1;
--
2.23.0