Mercurial > hg > nginx-quic
annotate src/os/win32/ngx_files.c @ 4401:d45742815c90
Fixed proxy_cache_use_stale in "no live upstreams" case.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 16 Jan 2012 11:01:52 +0000 |
parents | 4f4086cf1a07 |
children | d620f497c50f |
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 |
4017
4f4086cf1a07
Fix buffer overrun under Windows.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3651
diff
changeset
|
231 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
|
232 log); |
501 | 233 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
|
234 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
|
235 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
236 |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
237 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
|
238 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
239 collision = 0; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
240 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
241 /* 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
|
242 |
499 | 243 for ( ;; ) { |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
244 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
|
245 |
2900
812445a822e3
add trailing zero to a file name
Igor Sysoev <igor@sysoev.ru>
parents:
2782
diff
changeset
|
246 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
|
247 |
499 | 248 if (MoveFile((const char *) to->data, (const char *) name) != 0) { |
249 break; | |
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 |
499 | 252 collision = 1; |
253 | |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
254 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
|
255 "MoveFile() \"%s\" to \"%s\" failed", to->data, name); |
499 | 256 } |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
257 |
292
a472bfb778b3
nginx-0.0.3-2004-03-17-00:26:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
290
diff
changeset
|
258 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
|
259 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
|
260 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
261 } else { |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
262 err = 0; |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
263 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
264 |
1051 | 265 if (DeleteFile((const char *) name) == 0) { |
2901
17da2da3a8f5
fix logging in ngx_win32_rename_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2900
diff
changeset
|
266 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
|
267 "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
|
268 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
269 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
270 /* mutex_unlock() */ |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
271 |
1693
f4eb04fd8579
use malloc() in ngx_win32_rename_file, set crit level instead of error
Igor Sysoev <igor@sysoev.ru>
parents:
1634
diff
changeset
|
272 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
|
273 |
3382
6be1f25bae90
fix Win32 error messages when an temporary file replaces an existent file:
Igor Sysoev <igor@sysoev.ru>
parents:
3200
diff
changeset
|
274 return err; |
184
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 |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
183
diff
changeset
|
277 |
561 | 278 ngx_int_t |
2462
90d5ddfedbb1
use GetFileAttributesEx() instead of GetFileAttributes()
Igor Sysoev <igor@sysoev.ru>
parents:
2459
diff
changeset
|
279 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
|
280 { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
281 size_t len; |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
282 long rc; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
283 u_short *u; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
284 ngx_err_t err; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
285 WIN32_FILE_ATTRIBUTE_DATA fa; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
286 u_short utf16[NGX_UTF16_BUFLEN]; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
287 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
288 len = NGX_UTF16_BUFLEN; |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
289 |
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
290 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
|
291 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
292 if (u == NULL) { |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
293 return NGX_FILE_ERROR; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
294 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
295 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
296 rc = GetFileAttributesExW(u, GetFileExInfoStandard, &fa); |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
297 |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
298 if (u != utf16) { |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
299 err = ngx_errno; |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
300 ngx_free(u); |
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
301 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
|
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 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 |
3138
a2479937dbd8
win32 ngx_file_info() utf8 support
Igor Sysoev <igor@sysoev.ru>
parents:
3137
diff
changeset
|
311 return rc; |
185
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 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
314 |
561 | 315 ngx_int_t |
681 | 316 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) |
317 { | |
318 uint64_t intervals; | |
319 FILETIME ft; | |
320 | |
321 /* 116444736000000000 is commented in src/os/win32/ngx_time.c */ | |
322 | |
323 intervals = s * 10000000 + 116444736000000000; | |
324 | |
325 ft.dwLowDateTime = (DWORD) intervals; | |
326 ft.dwHighDateTime = (DWORD) (intervals >> 32); | |
327 | |
328 if (SetFileTime(fd, NULL, NULL, &ft) != 0) { | |
329 return NGX_OK; | |
330 } | |
331 | |
332 return NGX_ERROR; | |
333 } | |
334 | |
335 | |
3651 | 336 ngx_int_t |
337 ngx_create_file_mapping(ngx_file_mapping_t *fm) | |
338 { | |
339 LARGE_INTEGER size; | |
340 | |
341 fm->fd = ngx_open_file(fm->name, NGX_FILE_RDWR, NGX_FILE_TRUNCATE, | |
342 NGX_FILE_DEFAULT_ACCESS); | |
343 if (fm->fd == NGX_INVALID_FILE) { | |
344 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
345 ngx_open_file_n " \"%s\" failed", fm->name); | |
346 return NGX_ERROR; | |
347 } | |
348 | |
349 fm->handle = NULL; | |
350 | |
351 size.QuadPart = fm->size; | |
352 | |
353 if (SetFilePointerEx(fm->fd, size, NULL, FILE_BEGIN) == 0) { | |
354 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
355 "SetFilePointerEx(\"%s\", %uz) failed", | |
356 fm->name, fm->size); | |
357 goto failed; | |
358 } | |
359 | |
360 if (SetEndOfFile(fm->fd) == 0) { | |
361 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
362 "SetEndOfFile() \"%s\" failed", fm->name); | |
363 goto failed; | |
364 } | |
365 | |
366 fm->handle = CreateFileMapping(fm->fd, NULL, PAGE_READWRITE, | |
367 (u_long) ((off_t) fm->size >> 32), | |
368 (u_long) ((off_t) fm->size & 0xffffffff), | |
369 NULL); | |
370 if (fm->handle == NULL) { | |
371 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
372 "CreateFileMapping(%s, %uz) failed", | |
373 fm->name, fm->size); | |
374 goto failed; | |
375 } | |
376 | |
377 fm->addr = MapViewOfFile(fm->handle, FILE_MAP_WRITE, 0, 0, 0); | |
378 | |
379 if (fm->addr != NULL) { | |
380 return NGX_OK; | |
381 } | |
382 | |
383 ngx_log_error(NGX_LOG_CRIT, fm->log, ngx_errno, | |
384 "MapViewOfFile(%uz) of file mapping \"%s\" failed", | |
385 fm->size, fm->name); | |
386 | |
387 failed: | |
388 | |
389 if (fm->handle) { | |
390 if (CloseHandle(fm->handle) == 0) { | |
391 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
392 "CloseHandle() of file mapping \"%s\" failed", | |
393 fm->name); | |
394 } | |
395 } | |
396 | |
397 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
398 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
399 ngx_close_file_n " \"%s\" failed", fm->name); | |
400 } | |
401 | |
402 return NGX_ERROR; | |
403 } | |
404 | |
405 | |
406 void | |
407 ngx_close_file_mapping(ngx_file_mapping_t *fm) | |
408 { | |
409 if (UnmapViewOfFile(fm->addr) == 0) { | |
410 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
411 "UnmapViewOfFile(%p) of file mapping \"%s\" failed", | |
412 fm->addr, &fm->name); | |
413 } | |
414 | |
415 if (CloseHandle(fm->handle) == 0) { | |
416 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
417 "CloseHandle() of file mapping \"%s\" failed", | |
418 &fm->name); | |
419 } | |
420 | |
421 if (ngx_close_file(fm->fd) == NGX_FILE_ERROR) { | |
422 ngx_log_error(NGX_LOG_ALERT, fm->log, ngx_errno, | |
423 ngx_close_file_n " \"%s\" failed", fm->name); | |
424 } | |
425 } | |
426 | |
427 | |
2259 | 428 char * |
429 ngx_realpath(u_char *path, u_char *resolved) | |
430 { | |
431 /* STUB */ | |
432 return (char *) path; | |
433 } | |
434 | |
435 | |
561 | 436 ngx_int_t |
437 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
|
438 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
439 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
|
440 |
727 | 441 dir->dir = FindFirstFile((const char *) name->data, &dir->finddata); |
577 | 442 |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
443 if (dir->dir == INVALID_HANDLE_VALUE) { |
577 | 444 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
|
445 } |
577 | 446 |
457 | 447 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
|
448 dir->ready = 1; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
449 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
450 return NGX_OK; |
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 |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
453 |
561 | 454 ngx_int_t |
455 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
|
456 { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
457 if (dir->ready) { |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
458 dir->ready = 0; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
459 return NGX_OK; |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
460 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
461 |
727 | 462 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
|
463 dir->type = 1; |
681 | 464 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
|
465 } |
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
185
diff
changeset
|
466 |
681 | 467 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
|
468 } |
185
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
469 |
d5f50cefc322
nginx-0.0.1-2003-11-14-19:52:04 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
470 |
501 | 471 ngx_int_t |
727 | 472 ngx_open_glob(ngx_glob_t *gl) |
473 { | |
2459 | 474 u_char *p; |
475 size_t len; | |
476 ngx_err_t err; | |
1632 | 477 |
727 | 478 gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata); |
479 | |
480 if (gl->dir == INVALID_HANDLE_VALUE) { | |
1980 | 481 |
2459 | 482 err = ngx_errno; |
483 | |
484 if ((err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) | |
485 && gl->test) | |
486 { | |
1980 | 487 gl->no_match = 1; |
488 return NGX_OK; | |
489 } | |
490 | |
727 | 491 return NGX_ERROR; |
492 } | |
493 | |
1632 | 494 for (p = gl->pattern; *p; p++) { |
495 if (*p == '/') { | |
496 gl->last = p + 1 - gl->pattern; | |
497 } | |
498 } | |
499 | |
500 len = ngx_strlen(gl->finddata.cFileName); | |
501 gl->name.len = gl->last + len; | |
502 | |
503 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
504 if (gl->name.data == NULL) { | |
505 return NGX_ERROR; | |
506 } | |
507 | |
508 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
509 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
510 len + 1); | |
511 | |
727 | 512 gl->ready = 1; |
513 | |
514 return NGX_OK; | |
515 } | |
516 | |
517 | |
518 ngx_int_t | |
519 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name) | |
520 { | |
1632 | 521 size_t len; |
727 | 522 ngx_err_t err; |
523 | |
1980 | 524 if (gl->no_match) { |
525 return NGX_DONE; | |
526 } | |
527 | |
727 | 528 if (gl->ready) { |
1632 | 529 *name = gl->name; |
727 | 530 |
531 gl->ready = 0; | |
532 return NGX_OK; | |
533 } | |
534 | |
1632 | 535 ngx_free(gl->name.data); |
536 gl->name.data = NULL; | |
537 | |
727 | 538 if (FindNextFile(gl->dir, &gl->finddata) != 0) { |
1632 | 539 |
540 len = ngx_strlen(gl->finddata.cFileName); | |
541 gl->name.len = gl->last + len; | |
542 | |
543 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log); | |
544 if (gl->name.data == NULL) { | |
545 return NGX_ERROR; | |
546 } | |
547 | |
548 ngx_memcpy(gl->name.data, gl->pattern, gl->last); | |
549 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName, | |
550 len + 1); | |
551 | |
552 *name = gl->name; | |
727 | 553 |
554 return NGX_OK; | |
555 } | |
556 | |
557 err = ngx_errno; | |
558 | |
559 if (err == NGX_ENOMOREFILES) { | |
560 return NGX_DONE; | |
561 } | |
562 | |
563 ngx_log_error(NGX_LOG_ALERT, gl->log, err, | |
564 "FindNextFile(%s) failed", gl->pattern); | |
565 | |
566 return NGX_ERROR; | |
567 } | |
568 | |
569 | |
570 void | |
571 ngx_close_glob(ngx_glob_t *gl) | |
572 { | |
1632 | 573 if (gl->name.data) { |
574 ngx_free(gl->name.data); | |
575 } | |
576 | |
1980 | 577 if (gl->dir == INVALID_HANDLE_VALUE) { |
578 return; | |
579 } | |
580 | |
1632 | 581 if (FindClose(gl->dir) == 0) { |
727 | 582 ngx_log_error(NGX_LOG_ALERT, gl->log, ngx_errno, |
583 "FindClose(%s) failed", gl->pattern); | |
584 } | |
585 } | |
586 | |
587 | |
588 ngx_int_t | |
501 | 589 ngx_de_info(u_char *name, ngx_dir_t *dir) |
590 { | |
591 return NGX_OK; | |
592 } | |
593 | |
594 | |
595 ngx_int_t | |
596 ngx_de_link_info(u_char *name, ngx_dir_t *dir) | |
597 { | |
598 return NGX_OK; | |
599 } | |
600 | |
601 | |
561 | 602 ngx_int_t |
3178 | 603 ngx_read_ahead(ngx_fd_t fd, size_t n) |
604 { | |
605 return ~NGX_FILE_ERROR; | |
606 } | |
607 | |
608 | |
609 ngx_int_t | |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
610 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
|
611 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
612 return ~NGX_FILE_ERROR; |
2134
13652cba8633
fix building by bcc broken in r2130
Igor Sysoev <igor@sysoev.ru>
parents:
1980
diff
changeset
|
613 } |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
614 |
2615 | 615 |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
616 ngx_int_t |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
617 ngx_directio_off(ngx_fd_t fd) |
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
618 { |
3164
b1b1775698d5
uniform ngx_directio_on/off() interface with other file functions
Igor Sysoev <igor@sysoev.ru>
parents:
3158
diff
changeset
|
619 return ~NGX_FILE_ERROR; |
2248
1adec90a0e46
disable directio for unaligned reads in Linux
Igor Sysoev <igor@sysoev.ru>
parents:
2234
diff
changeset
|
620 } |
2615 | 621 |
622 | |
623 size_t | |
624 ngx_fs_bsize(u_char *name) | |
625 { | |
626 u_char root[4]; | |
627 u_long sc, bs, nfree, ncl; | |
628 | |
629 if (name[2] == ':') { | |
630 ngx_cpystrn(root, name, 4); | |
631 name = root; | |
632 } | |
633 | |
634 if (GetDiskFreeSpace((const char *) name, &sc, &bs, &nfree, &ncl) == 0) { | |
635 return 512; | |
636 } | |
637 | |
638 return sc * bs; | |
639 } | |
2628
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 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
642 static u_short * |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
643 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
|
644 { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
645 u_char *p; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
646 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
|
647 uint32_t n; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
648 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
649 p = utf8; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
650 u = utf16; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
651 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
|
652 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
653 while (u < last) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
654 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
655 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
656 *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
|
657 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
658 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
659 *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
|
660 return utf16; |
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 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
663 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
664 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
665 continue; |
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 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
668 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
|
669 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
670 if (n > 0xffff) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
671 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
|
672 return NULL; |
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 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
675 *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
|
676 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
677 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
678 /* 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
|
679 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
680 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
|
681 if (u == NULL) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
682 return NULL; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
683 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
684 |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
685 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
|
686 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
687 utf16 = u; |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
688 u += *len; |
2628
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
689 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
690 for ( ;; ) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
691 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
692 if (*p < 0x80) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
693 *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
|
694 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
695 if (*p == 0) { |
3417
15017418fd84
disable Win32 short file names
Igor Sysoev <igor@sysoev.ru>
parents:
3382
diff
changeset
|
696 *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
|
697 return utf16; |
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 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
700 p++; |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
701 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
702 continue; |
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 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
705 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
|
706 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
707 if (n > 0xffff) { |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
708 free(utf16); |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
709 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
|
710 return NULL; |
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 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
713 *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
|
714 } |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
715 |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
716 /* unreachable */ |
64a10d6b97bd
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
Igor Sysoev <igor@sysoev.ru>
parents:
2615
diff
changeset
|
717 } |