Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_files.c @ 3707:b9a64a91fe76
fix r3695: this commit
*) freed valid keys zone node
*) and did not decrease cache size, so cache manager process ete CPU time,
if cache checking max_size was enabled
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 27 Jul 2010 11:22:59 +0000 |
parents | 515d50917016 |
children | 4f4086cf1a07 |
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 |
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
|
4 */ |
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 |
42
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
6 |
cd035a94e0b6
nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents:
35
diff
changeset
|
7 #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
|
8 #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
|
9 |
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
11 #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
|
12 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
13 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
|
14 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
15 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
16 /* 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
|
17 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
18 ngx_fd_t |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
19 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
|
20 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
21 size_t len; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
22 u_long n; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
23 u_short *u, *lu; |
3137
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
24 ngx_fd_t fd; |
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
25 ngx_err_t err; |
179f6dfcb7fe
preserve errno while ngx_free()
Igor Sysoev <igor@sysoev.ru>
parents:
2974
diff
changeset
|
26 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
|
27 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
28 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
29 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
|
30 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
31 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
32 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
|
33 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
34 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
35 fd = INVALID_HANDLE_VALUE; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
36 lu = NULL; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
37 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
38 if (create == NGX_FILE_OPEN) { |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
39 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
40 lu = malloc(len * 2); |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
41 if (lu == NULL) { |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
42 goto failed; |
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 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
45 n = GetLongPathNameW(u, lu, len); |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
46 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
47 if (n == 0) { |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
48 goto failed; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
49 } |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
50 |
3458
bdcae1a576e3
compare long file names in case-insensitive mode,
Igor Sysoev <igor@sysoev.ru>
parents:
3417
diff
changeset
|
51 if (n != len - 1 || _wcsicmp(u, lu) != 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
52 ngx_set_errno(NGX_ENOENT); |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
53 goto failed; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
54 } |
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 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
|
58 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
|
59 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
|
60 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
61 failed: |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
62 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
63 err = ngx_errno; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
64 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
65 if (lu) { |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
66 ngx_free(lu); |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
67 } |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
68 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
69 if (u != utf16) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
70 ngx_free(u); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
71 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
72 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
73 ngx_set_errno(err); |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
74 |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
75 return fd; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
76 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
77 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
78 |
561 | 79 ssize_t |
80 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
|
81 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
82 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
|
83 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
|
84 OVERLAPPED ovlp, *povlp; |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 |
3156 | 86 ovlp.Internal = 0; |
87 ovlp.InternalHigh = 0; | |
88 ovlp.Offset = (u_long) offset; | |
89 ovlp.OffsetHigh = (u_long) (offset >> 32); | |
90 ovlp.hEvent = NULL; | |
461 | 91 |
3156 | 92 povlp = &ovlp; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
93 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
94 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
|
95 err = ngx_errno; |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
96 |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
97 if (err == ERROR_HANDLE_EOF) { |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
98 return 0; |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
99 } |
63f71723cd2a
handle Win32 ReadFile() EOF state in Unix way
Igor Sysoev <igor@sysoev.ru>
parents:
2901
diff
changeset
|
100 |
3157
a2c1b4f74ea7
log file name for read/write errors
Igor Sysoev <igor@sysoev.ru>
parents:
3156
diff
changeset
|
101 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
|
102 "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
|
103 return NGX_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
104 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
105 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
106 file->offset += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
107 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
108 return n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
109 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
110 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
111 |
561 | 112 ssize_t |
113 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
|
114 { |
290
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
280
diff
changeset
|
115 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
|
116 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
|
117 |
3156 | 118 ovlp.Internal = 0; |
119 ovlp.InternalHigh = 0; | |
120 ovlp.Offset = (u_long) offset; | |
121 ovlp.OffsetHigh = (u_long) (offset >> 32); | |
122 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
|
123 |
3156 | 124 povlp = &ovlp; |
183
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
125 |
4c698194c56d
nginx-0.0.1-2003-11-13-19:16:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
182
diff
changeset
|
126 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
|
127 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
|
128 "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
|
129 return NGX_ERROR; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
130 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
131 |
3158 | 132 if (n != size) { |
133 ngx_log_error(NGX_LOG_CRIT, file->log, 0, | |
134 "WriteFile() \"%s\" has written only %ul of %uz", | |
135 file->name.data, n, size); | |
136 return NGX_ERROR; | |
137 } | |
138 | |
182
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
139 file->offset += n; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
140 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
141 return n; |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
142 } |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
143 |
3c49eaf3f522
nginx-0.0.1-2003-11-13-09:14:05 import
Igor Sysoev <igor@sysoev.ru>
parents:
123
diff
changeset
|
144 |
561 | 145 ssize_t |
146 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, | |
147 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
|
148 { |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
149 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
|
150 size_t size; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
151 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
|
152 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
153 total = 0; |
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 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
|
156 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
|
157 prev = buf; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
158 size = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
159 |
344
e366ba5db8f8
nginx-0.0.3-2004-06-01-10:04:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
160 /* 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
|
161 |
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
|
162 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
|
163 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
|
164 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
|
165 cl = cl->next; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
166 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
167 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
168 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
|
169 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
170 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
|
171 return NGX_ERROR; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
172 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
173 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
174 total += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
175 offset += n; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
176 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
177 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
178 return total; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
179 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
180 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
181 |
1634
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
182 ssize_t |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
183 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
|
184 { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
185 u_long n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
186 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
187 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
|
188 return (size_t) n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
189 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
190 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
191 return -1; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
192 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
193 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
194 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
195 ssize_t |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
196 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
|
197 { |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
198 u_long n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
199 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
200 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
|
201 return (size_t) n; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
202 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
203 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
204 return -1; |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
205 } |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
206 |
d3cbb96818f1
fix win32 ngx_read_fd() and ngx_write_fd()
Igor Sysoev <igor@sysoev.ru>
parents:
1632
diff
changeset
|
207 |
2769
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
208 ssize_t |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
209 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
|
210 { |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
211 u_long n; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
212 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
213 (void) CharToOemBuff(buf, buf, size); |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
214 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
215 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
|
216 return (size_t) n; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
217 } |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
218 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
219 return -1; |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
220 } |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
221 |
9d986c4e796f
introduce ngx_write_console() to support OEM code pages
Igor Sysoev <igor@sysoev.ru>
parents:
2687
diff
changeset
|
222 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
223 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
|
224 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
|
225 { |
499 | 226 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
|
227 ngx_err_t err; |
499 | 228 ngx_uint_t collision; |
229 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
|
230 |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
231 name = ngx_alloc(to->len + 1 + 10 + 1 + sizeof("DELETE"), log); |
501 | 232 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
|
233 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
|
234 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
235 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
236 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
|
237 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
238 collision = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
239 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
240 /* 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
|
241 |
499 | 242 for ( ;; ) { |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
243 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
|
244 |
2900
812445a822e3
add trailing zero to a file name
Igor Sysoev <igor@sysoev.ru>
parents:
2782
diff
changeset
|
245 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
|
246 |
499 | 247 if (MoveFile((const char *) to->data, (const char *) name) != 0) { |
248 break; | |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
249 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
250 |
499 | 251 collision = 1; |
252 | |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
253 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
|
254 "MoveFile() \"%s\" to \"%s\" failed", to->data, name); |
499 | 255 } |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
256 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
257 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
|
258 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
|
259 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
260 } else { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
261 err = 0; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
262 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
263 |
1051 | 264 if (DeleteFile((const char *) name) == 0) { |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
265 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
|
266 "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
|
267 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
268 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
269 /* mutex_unlock() */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
270 |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
271 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
|
272 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
273 return err; |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
274 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
275 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
276 |
561 | 277 ngx_int_t |
2462
90d5ddfedbb1
use GetFileAttributesEx() instead of GetFileAttributes()
Igor Sysoev <igor@sysoev.ru>
parents:
2459
diff
changeset
|
278 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
|
279 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
280 size_t len; |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
281 long rc; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
282 u_short *u; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
283 ngx_err_t err; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
284 WIN32_FILE_ATTRIBUTE_DATA fa; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
285 u_short utf16[NGX_UTF16_BUFLEN]; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
286 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
287 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
288 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
289 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
|
290 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
291 if (u == NULL) { |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
292 return NGX_FILE_ERROR; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
293 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
294 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
295 rc = GetFileAttributesExW(u, GetFileExInfoStandard, &fa); |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
296 |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
297 if (u != utf16) { |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
298 err = ngx_errno; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
299 ngx_free(u); |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
300 ngx_set_errno(err); |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
301 } |
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 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
310 return rc; |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
311 } |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
312 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
313 |
561 | 314 ngx_int_t |
681 | 315 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
316 { | |
317 uint64_t intervals; | |
318 FILETIME ft; | |
319 | |
320 /* 116444736000000000 is commented in src/os/win32/ngx_time.c */ | |
321 | |
322 intervals = s * 10000000 + 116444736000000000; | |
323 | |
324 ft.dwLowDateTime = (DWORD) intervals; | |
325 ft.dwHighDateTime = (DWORD) (intervals >> 32); | |
326 | |
327 if (SetFileTime(fd, NULL, NULL, &ft) != 0) { | |
328 return NGX_OK; | |
329 } | |
330 | |
331 return NGX_ERROR; | |
332 } | |
333 | |
334 | |
3651 | 335 ngx_int_t |
336 ngx_create_file_mapping(ngx_file_mapping_t *fm) | |
337 { | |
338 LARGE_INTEGER size; | |
339 | |
340 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
341 NGX_FILE_DEFAULT_ACCESS); | |
342 if (fm->fd == NGX_INVALID_FILE) { | |
343 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
344 ngx_open_file_n " \"%s\" failed", fm->name); | |
345 return NGX_ERROR; | |
346 } | |
347 | |
348 fm->handle = NULL; | |
349 | |
350 size.QuadPart = fm->size; | |
351 | |
352 if (SetFilePointerEx(fm->fd, size, NULL, FILE_BEGIN) == 0) { | |
353 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
354 "SetFilePointerEx(\"%s\", %uz) failed", | |
355 fm->name, fm->size); | |
356 goto failed; | |
357 } | |
358 | |
359 if (SetEndOfFile(fm->fd) == 0) { | |
360 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
361 "SetEndOfFile() \"%s\" failed", fm->name); | |
362 goto failed; | |
363 } | |
364 | |
365 fm->handle = CreateFileMapping(fm->fd, NULL, PAGE_READWRITE, | |
366 (u_long) ((off_t) fm->size >> 32), | |
367 (u_long) ((off_t) fm->size & 0xffffffff), | |
368 NULL); | |
369 if (fm->handle == NULL) { | |
370 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
371 "CreateFileMapping(%s, %uz) failed", | |
372 fm->name, fm->size); | |
373 goto failed; | |
374 } | |
375 | |
376 fm->addr = MapViewOfFile(fm->handle, FILE_MAP_WRITE, 0, 0, 0); | |
377 | |
378 if (fm->addr != NULL) { | |
379 return NGX_OK; | |
380 } | |
381 | |
382 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
383 "MapViewOfFile(%uz) of file mapping \"%s\" failed", | |
384 fm->size, fm->name); | |
385 | |
386 failed: | |
387 | |
388 if (fm->handle) { | |
389 if (CloseHandle(fm->handle) == 0) { | |
390 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
391 "CloseHandle() of file mapping \"%s\" failed", | |
392 fm->name); | |
393 } | |
394 } | |
395 | |
396 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
397 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
398 ngx_close_file_n " \"%s\" failed", fm->name); | |
399 } | |
400 | |
401 return NGX_ERROR; | |
402 } | |
403 | |
404 | |
405 void | |
406 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
407 { | |
408 if (UnmapViewOfFile(fm->addr) == 0) { | |
409 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
410 "UnmapViewOfFile(%p) of file mapping \"%s\" failed", | |
411 fm->addr, &fm->name); | |
412 } | |
413 | |
414 if (CloseHandle(fm->handle) == 0) { | |
415 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
416 "CloseHandle() of file mapping \"%s\" failed", | |
417 &fm->name); | |
418 } | |
419 | |
420 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
421 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
422 ngx_close_file_n " \"%s\" failed", fm->name); | |
423 } | |
424 } | |
425 | |
426 | |
2259 | 427 char * |
428 ngx_realpath(u_char *path, u_char *resolved) | |
429 { | |
430 /* STUB */ | |
431 return (char *) path; | |
432 } | |
433 | |
434 | |
561 | 435 ngx_int_t |
436 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
|
437 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
438 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
|
439 |
727 | 440 dir->dir = FindFirstFile((const char *) name->data, &dir->finddata); |
577 | 441 |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
442 if (dir->dir == INVALID_HANDLE_VALUE) { |
577 | 443 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
|
444 } |
577 | 445 |
457 | 446 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
|
447 dir->ready = 1; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
448 |
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 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
452 |
561 | 453 ngx_int_t |
454 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
|
455 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
456 if (dir->ready) { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
457 dir->ready = 0; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
458 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
459 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
460 |
727 | 461 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
|
462 dir->type = 1; |
681 | 463 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
|
464 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
465 |
681 | 466 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
|
467 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
468 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
469 |
501 | 470 ngx_int_t |
727 | 471 ngx_open_glob(ngx_glob_t *gl) |
472 { | |
2459 | 473 u_char *p; |
474 size_t len; | |
475 ngx_err_t err; | |
1632 | 476 |
727 | 477 gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata); |
478 | |
479 if (gl->dir == INVALID_HANDLE_VALUE) { | |
1980 | 480 |
2459 | 481 err = ngx_errno; |
482 | |
483 if ((err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) | |
484 && gl->test) | |
485 { | |
1980 | 486 gl->no_match = 1; |
487 return NGX_OK; | |
488 } | |
489 | |
727 | 490 return NGX_ERROR; |
491 } | |
492 | |
1632 | 493 for (p = gl->pattern; *p; p++) { |
494 if (*p == '/') { | |
495 gl->last = p + 1 - gl->pattern; | |
496 } | |
497 } | |
498 | |
499 len = ngx_strlen(gl->finddata.cFileName); | |
500 gl->name.len = gl->last + len; | |
501 | |
502 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
503 if (gl->name.data == NULL) { | |
504 return NGX_ERROR; | |
505 } | |
506 | |
507 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
508 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
509 len + 1); | |
510 | |
727 | 511 gl->ready = 1; |
512 | |
513 return NGX_OK; | |
514 } | |
515 | |
516 | |
517 ngx_int_t | |
518 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
519 { | |
1632 | 520 size_t len; |
727 | 521 ngx_err_t err; |
522 | |
1980 | 523 if (gl->no_match) { |
524 return NGX_DONE; | |
525 } | |
526 | |
727 | 527 if (gl->ready) { |
1632 | 528 *name = gl->name; |
727 | 529 |
530 gl->ready = 0; | |
531 return NGX_OK; | |
532 } | |
533 | |
1632 | 534 ngx_free(gl->name.data); |
535 gl->name.data = NULL; | |
536 | |
727 | 537 if (FindNextFile(gl->dir, &gl->finddata) != 0) { |
1632 | 538 |
539 len = ngx_strlen(gl->finddata.cFileName); | |
540 gl->name.len = gl->last + len; | |
541 | |
542 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
543 if (gl->name.data == NULL) { | |
544 return NGX_ERROR; | |
545 } | |
546 | |
547 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
548 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
549 len + 1); | |
550 | |
551 *name = gl->name; | |
727 | 552 |
553 return NGX_OK; | |
554 } | |
555 | |
556 err = ngx_errno; | |
557 | |
558 if (err == NGX_ENOMOREFILES) { | |
559 return NGX_DONE; | |
560 } | |
561 | |
562 ngx_log_error(NGX_LOG_ALERT, gl->log, err, | |
563 "FindNextFile(%s) failed", gl->pattern); | |
564 | |
565 return NGX_ERROR; | |
566 } | |
567 | |
568 | |
569 void | |
570 ngx_close_glob(ngx_glob_t *gl) | |
571 { | |
1632 | 572 if (gl->name.data) { |
573 ngx_free(gl->name.data); | |
574 } | |
575 | |
1980 | 576 if (gl->dir == INVALID_HANDLE_VALUE) { |
577 return; | |
578 } | |
579 | |
1632 | 580 if (FindClose(gl->dir) == 0) { |
727 | 581 ngx_log_error(NGX_LOG_ALERT, gl->log, ngx_errno, |
582 "FindClose(%s) failed", gl->pattern); | |
583 } | |
584 } | |
585 | |
586 | |
587 ngx_int_t | |
501 | 588 ngx_de_info(u_char *name, ngx_dir_t *dir) |
589 { | |
590 return NGX_OK; | |
591 } | |
592 | |
593 | |
594 ngx_int_t | |
595 ngx_de_link_info(u_char *name, ngx_dir_t *dir) | |
596 { | |
597 return NGX_OK; | |
598 } | |
599 | |
600 | |
561 | 601 ngx_int_t |
3178 | 602 ngx_read_ahead(ngx_fd_t fd, size_t n) |
603 { | |
604 return ~NGX_FILE_ERROR; | |
605 } | |
606 | |
607 | |
608 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
609 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
|
610 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
611 return ~NGX_FILE_ERROR; |
2134
13652cba8633
fix building by bcc broken in r2130
Igor Sysoev <igor@sysoev.ru>
parents:
1980
diff
changeset
|
612 } |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
613 |
2615 | 614 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
615 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
616 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
617 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
618 return ~NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
619 } |
2615 | 620 |
621 | |
622 size_t | |
623 ngx_fs_bsize(u_char *name) | |
624 { | |
625 u_char root[4]; | |
626 u_long sc, bs, nfree, ncl; | |
627 | |
628 if (name[2] == ':') { | |
629 ngx_cpystrn(root, name, 4); | |
630 name = root; | |
631 } | |
632 | |
633 if (GetDiskFreeSpace((const char *) name, &sc, &bs, &nfree, &ncl) == 0) { | |
634 return 512; | |
635 } | |
636 | |
637 return sc * bs; | |
638 } | |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
639 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
640 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
641 static u_short * |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
642 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
|
643 { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
644 u_char *p; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
645 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
|
646 uint32_t n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
647 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
648 p = utf8; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
649 u = utf16; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
650 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
|
651 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
652 while (u < last) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
653 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
654 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
655 *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
|
656 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
657 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
658 *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
|
659 return utf16; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
660 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
661 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
662 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
663 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
664 continue; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
665 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
666 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
667 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
|
668 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
669 if (n > 0xffff) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
670 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
|
671 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
672 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
673 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
674 *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
|
675 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
676 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
677 /* 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
|
678 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
679 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
|
680 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
681 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
682 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
683 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
684 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
|
685 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
686 utf16 = u; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
687 u += *len; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
688 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
689 for ( ;; ) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
690 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
691 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
692 *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
|
693 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
694 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
695 *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
|
696 return utf16; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
697 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
698 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
699 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
700 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
701 continue; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
702 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
703 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
704 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
|
705 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
706 if (n > 0xffff) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
707 free(utf16); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
708 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
|
709 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
710 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
711 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
712 *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
|
713 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
714 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
715 /* unreachable */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
716 } |