Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_files.c @ 4907:01d3d3a185e9 stable-1.2
Merge of r4892: keepalive memory usage optimization.
The ngx_http_keepalive_handler() function is now trying to not
keep c->buffer's memory for idle connections.
This behaviour is consistent with the ngx_http_set_keepalive()
function and it should decrease memory usage in some cases (especially
if epoll/rtsig is used).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 13 Nov 2012 11:21:31 +0000 |
parents | 47936d1c98e9 |
children | dea321e5c021 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
6 |
42
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
7 |
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
8 #include <ngx_config.h> |
100
7ebc8b7fb816
nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents:
42
diff
changeset
|
9 #include <ngx_core.h> |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
12 #define NGX_UTF16_BUFLEN 256 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
13 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
14 static ngx_int_t ngx_win32_check_filename(u_char *name, u_short *u, |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
15 size_t len); |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
16 static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
17 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
18 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
19 /* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
20 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
21 ngx_fd_t |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
22 ngx_open_file(u_char *name, u_long mode, u_long create, u_long access) |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
23 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
24 size_t len; |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
25 u_short *u; |
3137
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
26 ngx_fd_t fd; |
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
27 ngx_err_t err; |
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
28 u_short utf16[NGX_UTF16_BUFLEN]; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
29 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
30 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
31 u = ngx_utf8_to_utf16(utf16, name, &len); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
32 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
33 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
34 return INVALID_HANDLE_VALUE; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
35 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
36 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
37 fd = INVALID_HANDLE_VALUE; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
38 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
39 if (create == NGX_FILE_OPEN |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
40 && ngx_win32_check_filename(name, u, len) != NGX_OK) |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
41 { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
42 goto failed; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
43 } |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
44 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
45 fd = CreateFileW(u, mode, |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
46 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
47 NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
48 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
49 failed: |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
50 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
51 if (u != utf16) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
52 err = ngx_errno; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
53 ngx_free(u); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
54 ngx_set_errno(err); |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
55 } |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
56 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
57 return fd; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
58 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
59 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
60 |
561 | 61 ssize_t |
62 ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
64 u_long n; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
65 ngx_err_t err; |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
66 OVERLAPPED ovlp, *povlp; |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 |
3156 | 68 ovlp.Internal = 0; |
69 ovlp.InternalHigh = 0; | |
70 ovlp.Offset = (u_long) offset; | |
71 ovlp.OffsetHigh = (u_long) (offset >> 32); | |
72 ovlp.hEvent = NULL; | |
461 | 73 |
3156 | 74 povlp = &ovlp; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
75 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
76 if (ReadFile(file->fd, buf, size, &n, povlp) == 0) { |
2974
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
77 err = ngx_errno; |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
78 |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
79 if (err == ERROR_HANDLE_EOF) { |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
80 return 0; |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
81 } |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
82 |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
83 ngx_log_error(NGX_LOG_ERR, file->log, err, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
84 "ReadFile() \"%s\" failed", file->name.data); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
85 return NGX_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
86 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
87 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
88 file->offset += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
89 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
90 return n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
91 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
92 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
93 |
561 | 94 ssize_t |
95 ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
96 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
97 u_long n; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
98 OVERLAPPED ovlp, *povlp; |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
99 |
3156 | 100 ovlp.Internal = 0; |
101 ovlp.InternalHigh = 0; | |
102 ovlp.Offset = (u_long) offset; | |
103 ovlp.OffsetHigh = (u_long) (offset >> 32); | |
104 ovlp.hEvent = NULL; | |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
105 |
3156 | 106 povlp = &ovlp; |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
107 |
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
108 if (WriteFile(file->fd, buf, size, &n, povlp) == 0) { |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
109 ngx_log_error(NGX_LOG_ERR, file->log, ngx_errno, |
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
110 "WriteFile() \"%s\" failed", file->name.data); |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
111 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
112 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
113 |
3158 | 114 if (n != size) { |
115 ngx_log_error(NGX_LOG_CRIT, file->log, 0, | |
116 "WriteFile() \"%s\" has written only %ul of %uz", | |
117 file->name.data, n, size); | |
118 return NGX_ERROR; | |
119 } | |
120 | |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
121 file->offset += n; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
122 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
123 return n; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
124 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
125 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
126 |
561 | 127 ssize_t |
128 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
129 ngx_pool_t *pool) | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
130 { |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
131 u_char *buf, *prev; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
132 size_t size; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
133 ssize_t total, n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
134 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
135 total = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
136 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
137 while (cl) { |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
138 buf = cl->buf->pos; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
139 prev = buf; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
140 size = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
141 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
142 /* coalesce the neighbouring bufs */ |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
143 |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
144 while (cl && prev == cl->buf->pos) { |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
145 size += cl->buf->last - cl->buf->pos; |
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
146 prev = cl->buf->last; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
147 cl = cl->next; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
148 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
149 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
150 n = ngx_write_file(file, buf, size, offset); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
151 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
152 if (n == NGX_ERROR) { |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
153 return NGX_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
154 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
155 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
156 total += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
157 offset += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
158 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
159 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
160 return total; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
161 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
162 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
163 |
1634
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
164 ssize_t |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
165 ngx_read_fd(ngx_fd_t fd, void *buf, size_t size) |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
166 { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
167 u_long n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
168 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
169 if (ReadFile(fd, buf, size, &n, NULL) != 0) { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
170 return (size_t) n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
171 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
172 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
173 return -1; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
174 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
175 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
176 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
177 ssize_t |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
178 ngx_write_fd(ngx_fd_t fd, void *buf, size_t size) |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
179 { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
180 u_long n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
181 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
182 if (WriteFile(fd, buf, size, &n, NULL) != 0) { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
183 return (size_t) n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
184 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
185 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
186 return -1; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
187 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
188 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
189 |
2769
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
190 ssize_t |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
191 ngx_write_console(ngx_fd_t fd, void *buf, size_t size) |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
192 { |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
193 u_long n; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
194 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
195 (void) CharToOemBuff(buf, buf, size); |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
196 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
197 if (WriteFile(fd, buf, size, &n, NULL) != 0) { |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
198 return (size_t) n; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
199 } |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
200 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
201 return -1; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
202 } |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
203 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
204 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
205 ngx_err_t |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
206 ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log) |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
207 { |
499 | 208 u_char *name; |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
209 ngx_err_t err; |
499 | 210 ngx_uint_t collision; |
211 ngx_atomic_uint_t num; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
212 |
4017
4f4086cf1a07
Fix buffer overrun under Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3651
diff
changeset
|
213 name = ngx_alloc(to->len + 1 + NGX_ATOMIC_T_LEN + 1 + sizeof("DELETE"), |
4f4086cf1a07
Fix buffer overrun under Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3651
diff
changeset
|
214 log); |
501 | 215 if (name == NULL) { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
216 return NGX_ENOMEM; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
217 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
218 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
219 ngx_memcpy(name, to->data, to->len); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
220 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
221 collision = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
222 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
223 /* mutex_lock() (per cache or single ?) */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
224 |
499 | 225 for ( ;; ) { |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
226 num = ngx_next_temp_number(collision); |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
227 |
2900
812445a822e3
add trailing zero to a file name
Igor Sysoev <igor@sysoev.ru>
parents:
2782
diff
changeset
|
228 ngx_sprintf(name + to->len, ".%0muA.DELETE%Z", num); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
229 |
499 | 230 if (MoveFile((const char *) to->data, (const char *) name) != 0) { |
231 break; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
232 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
233 |
499 | 234 collision = 1; |
235 | |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
236 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, |
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
237 "MoveFile() \"%s\" to \"%s\" failed", to->data, name); |
499 | 238 } |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
239 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
240 if (MoveFile((const char *) from->data, (const char *) to->data) == 0) { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
241 err = ngx_errno; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
242 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
243 } else { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
244 err = 0; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
245 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
246 |
1051 | 247 if (DeleteFile((const char *) name) == 0) { |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
248 ngx_log_error(NGX_LOG_CRIT, log, ngx_errno, |
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
249 "DeleteFile() \"%s\" failed", name); |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
250 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
251 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
252 /* mutex_unlock() */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
253 |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
254 ngx_free(name); |
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
255 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
256 return err; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
257 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
258 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
259 |
561 | 260 ngx_int_t |
2462
90d5ddfedbb1
use GetFileAttributesEx() instead of GetFileAttributes()
Igor Sysoev <igor@sysoev.ru>
parents:
2459
diff
changeset
|
261 ngx_file_info(u_char *file, ngx_file_info_t *sb) |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
262 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
263 size_t len; |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
264 long rc; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
265 u_short *u; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
266 ngx_err_t err; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
267 WIN32_FILE_ATTRIBUTE_DATA fa; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
268 u_short utf16[NGX_UTF16_BUFLEN]; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
269 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
270 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
271 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
272 u = ngx_utf8_to_utf16(utf16, file, &len); |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
273 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
274 if (u == NULL) { |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
275 return NGX_FILE_ERROR; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
276 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
277 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
278 rc = NGX_FILE_ERROR; |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
279 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
280 if (ngx_win32_check_filename(file, u, len) != NGX_OK) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
281 goto failed; |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
282 } |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
283 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
284 rc = GetFileAttributesExW(u, GetFileExInfoStandard, &fa); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
285 |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
286 sb->dwFileAttributes = fa.dwFileAttributes; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
287 sb->ftCreationTime = fa.ftCreationTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
288 sb->ftLastAccessTime = fa.ftLastAccessTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
289 sb->ftLastWriteTime = fa.ftLastWriteTime; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
290 sb->nFileSizeHigh = fa.nFileSizeHigh; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
291 sb->nFileSizeLow = fa.nFileSizeLow; |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
292 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
293 failed: |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
294 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
295 if (u != utf16) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
296 err = ngx_errno; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
297 ngx_free(u); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
298 ngx_set_errno(err); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
299 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
300 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
301 return rc; |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
302 } |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
303 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
304 |
561 | 305 ngx_int_t |
681 | 306 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
307 { | |
308 uint64_t intervals; | |
309 FILETIME ft; | |
310 | |
311 /* 116444736000000000 is commented in src/os/win32/ngx_time.c */ | |
312 | |
313 intervals = s * 10000000 + 116444736000000000; | |
314 | |
315 ft.dwLowDateTime = (DWORD) intervals; | |
316 ft.dwHighDateTime = (DWORD) (intervals >> 32); | |
317 | |
318 if (SetFileTime(fd, NULL, NULL, &ft) != 0) { | |
319 return NGX_OK; | |
320 } | |
321 | |
322 return NGX_ERROR; | |
323 } | |
324 | |
325 | |
3651 | 326 ngx_int_t |
327 ngx_create_file_mapping(ngx_file_mapping_t *fm) | |
328 { | |
329 LARGE_INTEGER size; | |
330 | |
331 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
332 NGX_FILE_DEFAULT_ACCESS); | |
333 if (fm->fd == NGX_INVALID_FILE) { | |
334 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
335 ngx_open_file_n " \"%s\" failed", fm->name); | |
336 return NGX_ERROR; | |
337 } | |
338 | |
339 fm->handle = NULL; | |
340 | |
341 size.QuadPart = fm->size; | |
342 | |
343 if (SetFilePointerEx(fm->fd, size, NULL, FILE_BEGIN) == 0) { | |
344 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
345 "SetFilePointerEx(\"%s\", %uz) failed", | |
346 fm->name, fm->size); | |
347 goto failed; | |
348 } | |
349 | |
350 if (SetEndOfFile(fm->fd) == 0) { | |
351 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
352 "SetEndOfFile() \"%s\" failed", fm->name); | |
353 goto failed; | |
354 } | |
355 | |
356 fm->handle = CreateFileMapping(fm->fd, NULL, PAGE_READWRITE, | |
357 (u_long) ((off_t) fm->size >> 32), | |
358 (u_long) ((off_t) fm->size & 0xffffffff), | |
359 NULL); | |
360 if (fm->handle == NULL) { | |
361 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
362 "CreateFileMapping(%s, %uz) failed", | |
363 fm->name, fm->size); | |
364 goto failed; | |
365 } | |
366 | |
367 fm->addr = MapViewOfFile(fm->handle, FILE_MAP_WRITE, 0, 0, 0); | |
368 | |
369 if (fm->addr != NULL) { | |
370 return NGX_OK; | |
371 } | |
372 | |
373 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
374 "MapViewOfFile(%uz) of file mapping \"%s\" failed", | |
375 fm->size, fm->name); | |
376 | |
377 failed: | |
378 | |
379 if (fm->handle) { | |
380 if (CloseHandle(fm->handle) == 0) { | |
381 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
382 "CloseHandle() of file mapping \"%s\" failed", | |
383 fm->name); | |
384 } | |
385 } | |
386 | |
387 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
388 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
389 ngx_close_file_n " \"%s\" failed", fm->name); | |
390 } | |
391 | |
392 return NGX_ERROR; | |
393 } | |
394 | |
395 | |
396 void | |
397 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
398 { | |
399 if (UnmapViewOfFile(fm->addr) == 0) { | |
400 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
401 "UnmapViewOfFile(%p) of file mapping \"%s\" failed", | |
402 fm->addr, &fm->name); | |
403 } | |
404 | |
405 if (CloseHandle(fm->handle) == 0) { | |
406 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
407 "CloseHandle() of file mapping \"%s\" failed", | |
408 &fm->name); | |
409 } | |
410 | |
411 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
412 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
413 ngx_close_file_n " \"%s\" failed", fm->name); | |
414 } | |
415 } | |
416 | |
417 | |
4564
13eb3193cd63
Fixed win32 build after realpath changes in r4559.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
418 u_char * |
2259 | 419 ngx_realpath(u_char *path, u_char *resolved) |
420 { | |
421 /* STUB */ | |
4564
13eb3193cd63
Fixed win32 build after realpath changes in r4559.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
422 return path; |
2259 | 423 } |
424 | |
425 | |
561 | 426 ngx_int_t |
427 ngx_open_dir(ngx_str_t *name, ngx_dir_t *dir) | |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
428 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
429 ngx_cpystrn(name->data + name->len, NGX_DIR_MASK, NGX_DIR_MASK_LEN + 1); |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
430 |
727 | 431 dir->dir = FindFirstFile((const char *) name->data, &dir->finddata); |
577 | 432 |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
433 if (dir->dir == INVALID_HANDLE_VALUE) { |
577 | 434 return NGX_ERROR; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
435 } |
577 | 436 |
457 | 437 dir->valid_info = 1; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
438 dir->ready = 1; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
439 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
440 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
441 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
442 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
443 |
561 | 444 ngx_int_t |
445 ngx_read_dir(ngx_dir_t *dir) | |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
446 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
447 if (dir->ready) { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
448 dir->ready = 0; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
449 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
450 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
451 |
727 | 452 if (FindNextFile(dir->dir, &dir->finddata) != 0) { |
3200
26784c34e8be
*) reset cached dirent.d_type after stat()
Igor Sysoev <igor@sysoev.ru>
parents:
3178
diff
changeset
|
453 dir->type = 1; |
681 | 454 return NGX_OK; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
455 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
456 |
681 | 457 return NGX_ERROR; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
458 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
459 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
460 |
501 | 461 ngx_int_t |
727 | 462 ngx_open_glob(ngx_glob_t *gl) |
463 { | |
2459 | 464 u_char *p; |
465 size_t len; | |
466 ngx_err_t err; | |
1632 | 467 |
727 | 468 gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata); |
469 | |
470 if (gl->dir == INVALID_HANDLE_VALUE) { | |
1980 | 471 |
2459 | 472 err = ngx_errno; |
473 | |
474 if ((err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) | |
475 && gl->test) | |
476 { | |
1980 | 477 gl->no_match = 1; |
478 return NGX_OK; | |
479 } | |
480 | |
727 | 481 return NGX_ERROR; |
482 } | |
483 | |
1632 | 484 for (p = gl->pattern; *p; p++) { |
485 if (*p == '/') { | |
486 gl->last = p + 1 - gl->pattern; | |
487 } | |
488 } | |
489 | |
490 len = ngx_strlen(gl->finddata.cFileName); | |
491 gl->name.len = gl->last + len; | |
492 | |
493 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
494 if (gl->name.data == NULL) { | |
495 return NGX_ERROR; | |
496 } | |
497 | |
498 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
499 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
500 len + 1); | |
501 | |
727 | 502 gl->ready = 1; |
503 | |
504 return NGX_OK; | |
505 } | |
506 | |
507 | |
508 ngx_int_t | |
509 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
510 { | |
1632 | 511 size_t len; |
727 | 512 ngx_err_t err; |
513 | |
1980 | 514 if (gl->no_match) { |
515 return NGX_DONE; | |
516 } | |
517 | |
727 | 518 if (gl->ready) { |
1632 | 519 *name = gl->name; |
727 | 520 |
521 gl->ready = 0; | |
522 return NGX_OK; | |
523 } | |
524 | |
1632 | 525 ngx_free(gl->name.data); |
526 gl->name.data = NULL; | |
527 | |
727 | 528 if (FindNextFile(gl->dir, &gl->finddata) != 0) { |
1632 | 529 |
530 len = ngx_strlen(gl->finddata.cFileName); | |
531 gl->name.len = gl->last + len; | |
532 | |
533 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
534 if (gl->name.data == NULL) { | |
535 return NGX_ERROR; | |
536 } | |
537 | |
538 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
539 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
540 len + 1); | |
541 | |
542 *name = gl->name; | |
727 | 543 |
544 return NGX_OK; | |
545 } | |
546 | |
547 err = ngx_errno; | |
548 | |
549 if (err == NGX_ENOMOREFILES) { | |
550 return NGX_DONE; | |
551 } | |
552 | |
553 ngx_log_error(NGX_LOG_ALERT, gl->log, err, | |
554 "FindNextFile(%s) failed", gl->pattern); | |
555 | |
556 return NGX_ERROR; | |
557 } | |
558 | |
559 | |
560 void | |
561 ngx_close_glob(ngx_glob_t *gl) | |
562 { | |
1632 | 563 if (gl->name.data) { |
564 ngx_free(gl->name.data); | |
565 } | |
566 | |
1980 | 567 if (gl->dir == INVALID_HANDLE_VALUE) { |
568 return; | |
569 } | |
570 | |
1632 | 571 if (FindClose(gl->dir) == 0) { |
727 | 572 ngx_log_error(NGX_LOG_ALERT, gl->log, ngx_errno, |
573 "FindClose(%s) failed", gl->pattern); | |
574 } | |
575 } | |
576 | |
577 | |
578 ngx_int_t | |
501 | 579 ngx_de_info(u_char *name, ngx_dir_t *dir) |
580 { | |
581 return NGX_OK; | |
582 } | |
583 | |
584 | |
585 ngx_int_t | |
586 ngx_de_link_info(u_char *name, ngx_dir_t *dir) | |
587 { | |
588 return NGX_OK; | |
589 } | |
590 | |
591 | |
561 | 592 ngx_int_t |
3178 | 593 ngx_read_ahead(ngx_fd_t fd, size_t n) |
594 { | |
595 return ~NGX_FILE_ERROR; | |
596 } | |
597 | |
598 | |
599 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
600 ngx_directio_on(ngx_fd_t fd) |
2134
13652cba8633
fix building by bcc broken in r2130
Igor Sysoev <igor@sysoev.ru>
parents:
1980
diff
changeset
|
601 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
602 return ~NGX_FILE_ERROR; |
2134
13652cba8633
fix building by bcc broken in r2130
Igor Sysoev <igor@sysoev.ru>
parents:
1980
diff
changeset
|
603 } |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
604 |
2615 | 605 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
606 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
607 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
608 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
609 return ~NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
610 } |
2615 | 611 |
612 | |
613 size_t | |
614 ngx_fs_bsize(u_char *name) | |
615 { | |
616 u_char root[4]; | |
617 u_long sc, bs, nfree, ncl; | |
618 | |
619 if (name[2] == ':') { | |
620 ngx_cpystrn(root, name, 4); | |
621 name = root; | |
622 } | |
623 | |
624 if (GetDiskFreeSpace((const char *) name, &sc, &bs, &nfree, &ncl) == 0) { | |
625 return 512; | |
626 } | |
627 | |
628 return sc * bs; | |
629 } | |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
630 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
631 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
632 static ngx_int_t |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
633 ngx_win32_check_filename(u_char *name, u_short *u, size_t len) |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
634 { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
635 u_char *p, ch; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
636 u_long n; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
637 u_short *lu; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
638 ngx_err_t err; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
639 enum { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
640 sw_start = 0, |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
641 sw_normal, |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
642 sw_after_slash, |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
643 sw_after_colon, |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
644 sw_after_dot |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
645 } state; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
646 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
647 /* check for NTFS streams (":"), trailing dots and spaces */ |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
648 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
649 lu = NULL; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
650 state = sw_start; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
651 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
652 for (p = name; *p; p++) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
653 ch = *p; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
654 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
655 switch (state) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
656 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
657 case sw_start: |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
658 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
659 /* |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
660 * skip till first "/" to allow paths starting with drive and |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
661 * relative path, like "c:html/" |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
662 */ |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
663 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
664 if (ch == '/' || ch == '\\') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
665 state = sw_after_slash; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
666 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
667 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
668 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
669 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
670 case sw_normal: |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
671 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
672 if (ch == ':') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
673 state = sw_after_colon; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
674 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
675 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
676 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
677 if (ch == '.' || ch == ' ') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
678 state = sw_after_dot; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
679 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
680 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
681 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
682 if (ch == '/' || ch == '\\') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
683 state = sw_after_slash; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
684 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
685 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
686 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
687 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
688 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
689 case sw_after_slash: |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
690 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
691 if (ch == '/' || ch == '\\') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
692 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
693 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
694 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
695 if (ch == '.') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
696 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
697 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
698 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
699 if (ch == ':') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
700 state = sw_after_colon; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
701 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
702 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
703 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
704 state = sw_normal; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
705 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
706 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
707 case sw_after_colon: |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
708 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
709 if (ch == '/' || ch == '\\') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
710 state = sw_after_slash; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
711 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
712 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
713 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
714 goto invalid; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
715 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
716 case sw_after_dot: |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
717 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
718 if (ch == '/' || ch == '\\') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
719 goto invalid; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
720 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
721 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
722 if (ch == ':') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
723 goto invalid; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
724 } |
4725
47936d1c98e9
Merge of r4682, r4694, r4699, r4704, r4705: minor nits.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4678
diff
changeset
|
725 |
4678
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
726 if (ch == '.' || ch == ' ') { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
727 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
728 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
729 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
730 state = sw_normal; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
731 break; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
732 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
733 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
734 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
735 if (state == sw_after_dot) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
736 goto invalid; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
737 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
738 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
739 /* check if long name match */ |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
740 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
741 lu = malloc(len * 2); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
742 if (lu == NULL) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
743 return NGX_ERROR; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
744 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
745 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
746 n = GetLongPathNameW(u, lu, len); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
747 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
748 if (n == 0) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
749 goto failed; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
750 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
751 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
752 if (n != len - 1 || _wcsicmp(u, lu) != 0) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
753 goto invalid; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
754 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
755 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
756 return NGX_OK; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
757 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
758 invalid: |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
759 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
760 ngx_set_errno(NGX_ENOENT); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
761 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
762 failed: |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
763 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
764 if (lu) { |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
765 err = ngx_errno; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
766 ngx_free(lu); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
767 ngx_set_errno(err); |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
768 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
769 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
770 return NGX_ERROR; |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
771 } |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
772 |
01dbbe7236ee
Merge of r4674, r4675, r4676: win32 fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4564
diff
changeset
|
773 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
774 static u_short * |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
775 ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t *len) |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
776 { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
777 u_char *p; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
778 u_short *u, *last; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
779 uint32_t n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
780 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
781 p = utf8; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
782 u = utf16; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
783 last = utf16 + *len; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
784 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
785 while (u < last) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
786 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
787 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
788 *u++ = (u_short) *p; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
789 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
790 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
791 *len = u - utf16; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
792 return utf16; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
793 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
794 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
795 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
796 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
797 continue; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
798 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
799 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
800 n = ngx_utf8_decode(&p, 4); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
801 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
802 if (n > 0xffff) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
803 ngx_set_errno(NGX_EILSEQ); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
804 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
805 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
806 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
807 *u++ = (u_short) n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
808 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
809 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
810 /* the given buffer is not enough, allocate a new one */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
811 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
812 u = malloc(((p - utf8) + ngx_strlen(p) + 1) * sizeof(u_short)); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
813 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
814 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
815 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
816 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
817 ngx_memcpy(u, utf16, *len * 2); |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
818 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
819 utf16 = u; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
820 u += *len; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
821 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
822 for ( ;; ) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
823 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
824 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
825 *u++ = (u_short) *p; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
826 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
827 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
828 *len = u - utf16; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
829 return utf16; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
830 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
831 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
832 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
833 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
834 continue; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
835 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
836 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
837 n = ngx_utf8_decode(&p, 4); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
838 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
839 if (n > 0xffff) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
840 free(utf16); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
841 ngx_set_errno(NGX_EILSEQ); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
842 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
843 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
844 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
845 *u++ = (u_short) n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
846 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
847 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
848 /* unreachable */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
849 } |