mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
win32 ngx_open_file() supports utf8 names and NGX_FILE_APPEND
This commit is contained in:
parent
8017a63cb3
commit
fadc7a7e81
@ -359,8 +359,9 @@ ngx_init_cycle(ngx_cycle_t *old_cycle)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
file[i].fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR,
|
file[i].fd = ngx_open_file(file[i].name.data,
|
||||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND,
|
NGX_FILE_RDWR|NGX_FILE_APPEND,
|
||||||
|
NGX_FILE_CREATE_OR_OPEN,
|
||||||
NGX_FILE_DEFAULT_ACCESS);
|
NGX_FILE_DEFAULT_ACCESS);
|
||||||
|
|
||||||
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
|
ngx_log_debug3(NGX_LOG_DEBUG_CORE, log, 0,
|
||||||
@ -1064,9 +1065,8 @@ ngx_reopen_files(ngx_cycle_t *cycle, ngx_uid_t user)
|
|||||||
file[i].pos = file[i].buffer;
|
file[i].pos = file[i].buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR,
|
fd = ngx_open_file(file[i].name.data, NGX_FILE_RDWR|NGX_FILE_APPEND,
|
||||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND,
|
NGX_FILE_CREATE_OR_OPEN, NGX_FILE_DEFAULT_ACCESS);
|
||||||
NGX_FILE_DEFAULT_ACCESS);
|
|
||||||
|
|
||||||
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, cycle->log, 0,
|
||||||
"reopen file \"%s\", old:%d new:%d",
|
"reopen file \"%s\", old:%d new:%d",
|
||||||
|
@ -200,8 +200,10 @@ ngx_log_init(void)
|
|||||||
|
|
||||||
ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE);
|
ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE);
|
||||||
|
|
||||||
ngx_stderr.fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR,
|
ngx_stderr.fd = ngx_open_file((u_char *) NGX_ERROR_LOG_PATH,
|
||||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND, 0);
|
NGX_FILE_RDWR|NGX_FILE_APPEND,
|
||||||
|
NGX_FILE_CREATE_OR_OPEN,
|
||||||
|
NGX_FILE_DEFAULT_ACCESS);
|
||||||
|
|
||||||
if (ngx_stderr.fd == NGX_INVALID_FILE) {
|
if (ngx_stderr.fd == NGX_INVALID_FILE) {
|
||||||
ngx_message_box("nginx", MB_OK, ngx_errno,
|
ngx_message_box("nginx", MB_OK, ngx_errno,
|
||||||
@ -210,14 +212,6 @@ ngx_log_init(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_file_append_mode(ngx_stderr.fd) == NGX_ERROR) {
|
|
||||||
ngx_message_box("nginx", MB_OK, ngx_errno,
|
|
||||||
"Could not open error log file: "
|
|
||||||
ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH
|
|
||||||
"\" failed");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
ngx_stderr.fd = STDERR_FILENO;
|
ngx_stderr.fd = STDERR_FILENO;
|
||||||
|
@ -466,9 +466,8 @@ ngx_open_and_stat_file(u_char *name, ngx_open_file_info_t *of, ngx_log_t *log)
|
|||||||
fd = ngx_open_file(name, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
|
fd = ngx_open_file(name, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fd = ngx_open_file(name, NGX_FILE_RDWR,
|
fd = ngx_open_file(name, NGX_FILE_RDWR|NGX_FILE_APPEND,
|
||||||
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND,
|
NGX_FILE_CREATE_OR_OPEN, NGX_FILE_DEFAULT_ACCESS);
|
||||||
NGX_FILE_DEFAULT_ACCESS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd == NGX_INVALID_FILE) {
|
if (fd == NGX_INVALID_FILE) {
|
||||||
|
@ -44,6 +44,7 @@ typedef int ngx_err_t;
|
|||||||
#define NGX_EHOSTUNREACH EHOSTUNREACH
|
#define NGX_EHOSTUNREACH EHOSTUNREACH
|
||||||
#define NGX_ENOSYS ENOSYS
|
#define NGX_ENOSYS ENOSYS
|
||||||
#define NGX_ECANCELED ECANCELED
|
#define NGX_ECANCELED ECANCELED
|
||||||
|
#define NGX_EILSEQ EILSEQ
|
||||||
#define NGX_ENOMOREFILES 0
|
#define NGX_ENOMOREFILES 0
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ typedef DWORD ngx_err_t;
|
|||||||
#define NGX_EHOSTDOWN WSAEHOSTDOWN
|
#define NGX_EHOSTDOWN WSAEHOSTDOWN
|
||||||
#define NGX_EHOSTUNREACH WSAEHOSTUNREACH
|
#define NGX_EHOSTUNREACH WSAEHOSTUNREACH
|
||||||
#define NGX_ENOMOREFILES ERROR_NO_MORE_FILES
|
#define NGX_ENOMOREFILES ERROR_NO_MORE_FILES
|
||||||
|
#define NGX_EILSEQ ERROR_NO_UNICODE_TRANSLATION
|
||||||
|
|
||||||
#define NGX_EALREADY WSAEALREADY
|
#define NGX_EALREADY WSAEALREADY
|
||||||
#define NGX_EINVAL WSAEINVAL
|
#define NGX_EINVAL WSAEINVAL
|
||||||
|
@ -8,6 +8,38 @@
|
|||||||
#include <ngx_core.h>
|
#include <ngx_core.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define NGX_UTF16_BUFLEN 256
|
||||||
|
|
||||||
|
static u_short *ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t len);
|
||||||
|
|
||||||
|
|
||||||
|
/* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory */
|
||||||
|
|
||||||
|
ngx_fd_t
|
||||||
|
ngx_open_file(u_char *name, u_long mode, u_long create, u_long access)
|
||||||
|
{
|
||||||
|
u_short *u;
|
||||||
|
ngx_fd_t fd;
|
||||||
|
u_short utf16[NGX_UTF16_BUFLEN];
|
||||||
|
|
||||||
|
u = ngx_utf8_to_utf16(utf16, name, NGX_UTF16_BUFLEN);
|
||||||
|
|
||||||
|
if (u == NULL) {
|
||||||
|
return INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
fd = CreateFileW(u, mode,
|
||||||
|
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
|
||||||
|
NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||||
|
|
||||||
|
if (u != utf16) {
|
||||||
|
ngx_free(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
|
ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset)
|
||||||
{
|
{
|
||||||
@ -529,3 +561,82 @@ ngx_fs_bsize(u_char *name)
|
|||||||
|
|
||||||
return sc * bs;
|
return sc * bs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static u_short *
|
||||||
|
ngx_utf8_to_utf16(u_short *utf16, u_char *utf8, size_t len)
|
||||||
|
{
|
||||||
|
u_char *p;
|
||||||
|
u_short *u, *last;
|
||||||
|
uint32_t n;
|
||||||
|
|
||||||
|
p = utf8;
|
||||||
|
u = utf16;
|
||||||
|
last = utf16 + len;
|
||||||
|
|
||||||
|
while (u < last) {
|
||||||
|
|
||||||
|
if (*p < 0x80) {
|
||||||
|
*u = (u_short) *p;
|
||||||
|
|
||||||
|
if (*p == 0) {
|
||||||
|
return utf16;
|
||||||
|
}
|
||||||
|
|
||||||
|
u++;
|
||||||
|
p++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ngx_utf8_decode(&p, 4);
|
||||||
|
|
||||||
|
if (n > 0xffff) {
|
||||||
|
free(utf16);
|
||||||
|
ngx_set_errno(NGX_EILSEQ);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*u++ = (u_short) n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the given buffer is not enough, allocate a new one */
|
||||||
|
|
||||||
|
u = malloc(((p - utf8) + ngx_strlen(p) + 1) * sizeof(u_short));
|
||||||
|
if (u == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_memcpy(u, utf16, len * 2);
|
||||||
|
|
||||||
|
utf16 = u;
|
||||||
|
u += len;
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
|
|
||||||
|
if (*p < 0x80) {
|
||||||
|
*u = (u_short) *p;
|
||||||
|
|
||||||
|
if (*p == 0) {
|
||||||
|
return utf16;
|
||||||
|
}
|
||||||
|
|
||||||
|
u++;
|
||||||
|
p++;
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = ngx_utf8_decode(&p, 4);
|
||||||
|
|
||||||
|
if (n > 0xffff) {
|
||||||
|
free(utf16);
|
||||||
|
ngx_set_errno(NGX_EILSEQ);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*u++ = (u_short) n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* unreachable */
|
||||||
|
}
|
||||||
|
@ -57,22 +57,16 @@ typedef struct {
|
|||||||
#define NGX_FILE_ERROR 0
|
#define NGX_FILE_ERROR 0
|
||||||
|
|
||||||
|
|
||||||
/*
|
ngx_fd_t ngx_open_file(u_char *name, u_long mode, u_long create, u_long access);
|
||||||
* FILE_FLAG_BACKUP_SEMANTICS allows to obtain a handle to a directory
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define ngx_open_file(name, mode, create, access) \
|
|
||||||
CreateFile((const char *) name, mode, \
|
|
||||||
FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, \
|
|
||||||
NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL)
|
|
||||||
#define ngx_open_file_n "CreateFile()"
|
#define ngx_open_file_n "CreateFile()"
|
||||||
|
|
||||||
#define NGX_FILE_RDONLY GENERIC_READ
|
#define NGX_FILE_RDONLY GENERIC_READ
|
||||||
#define NGX_FILE_WRONLY GENERIC_WRITE
|
#define NGX_FILE_WRONLY GENERIC_WRITE
|
||||||
#define NGX_FILE_RDWR GENERIC_READ|GENERIC_WRITE
|
#define NGX_FILE_RDWR GENERIC_READ|GENERIC_WRITE
|
||||||
|
#define NGX_FILE_APPEND FILE_APPEND_DATA|SYNCHRONIZE
|
||||||
|
|
||||||
#define NGX_FILE_CREATE_OR_OPEN OPEN_ALWAYS
|
#define NGX_FILE_CREATE_OR_OPEN OPEN_ALWAYS
|
||||||
#define NGX_FILE_OPEN OPEN_EXISTING
|
#define NGX_FILE_OPEN OPEN_EXISTING
|
||||||
#define NGX_FILE_APPEND 0
|
|
||||||
|
|
||||||
#define NGX_FILE_DEFAULT_ACCESS 0
|
#define NGX_FILE_DEFAULT_ACCESS 0
|
||||||
#define NGX_FILE_OWNER_ACCESS 0
|
#define NGX_FILE_OWNER_ACCESS 0
|
||||||
|
Loading…
Reference in New Issue
Block a user