From 89cf9f77871503cad037f5d914ca11f7a65f9a1e Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 28 Apr 2009 15:05:27 +0000 Subject: [PATCH] introduce ngx_write_console() to support OEM code pages --- src/core/ngx_log.c | 4 ++-- src/os/unix/ngx_files.h | 4 ++++ src/os/win32/ngx_files.c | 15 +++++++++++++++ src/os/win32/ngx_files.h | 3 +++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index 3fb697b7d..fe638781c 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -152,7 +152,7 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, (void) ngx_sprintf(msg, "[%V]: ", &err_levels[level]); - (void) ngx_write_fd(ngx_stderr, msg, p - msg); + (void) ngx_write_console(ngx_stderr, msg, p - msg); } @@ -224,7 +224,7 @@ ngx_log_stderr(ngx_err_t err, const char *fmt, ...) ngx_linefeed(p); - (void) ngx_write_fd(ngx_stderr, errstr, p - errstr); + (void) ngx_write_console(ngx_stderr, errstr, p - errstr); } diff --git a/src/os/unix/ngx_files.h b/src/os/unix/ngx_files.h index 8608e173d..cf5c3ed91 100644 --- a/src/os/unix/ngx_files.h +++ b/src/os/unix/ngx_files.h @@ -113,6 +113,10 @@ ngx_write_fd(ngx_fd_t fd, void *buf, size_t n) #define ngx_write_fd_n "write()" + +#define ngx_write_console ngx_write_fd + + #define ngx_linefeed(p) *p++ = LF; #define NGX_LINEFEED_SIZE 1 diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c index 79f42b13b..e10bce3ae 100644 --- a/src/os/win32/ngx_files.c +++ b/src/os/win32/ngx_files.c @@ -232,6 +232,21 @@ ngx_write_fd(ngx_fd_t fd, void *buf, size_t size) } +ssize_t +ngx_write_console(ngx_fd_t fd, void *buf, size_t size) +{ + u_long n; + + (void) CharToOemBuff(buf, buf, size); + + if (WriteFile(fd, buf, size, &n, NULL) != 0) { + return (size_t) n; + } + + return -1; +} + + ngx_int_t ngx_win32_rename_file(ngx_str_t *from, ngx_str_t *to, ngx_log_t *log) { diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h index 2abaaf5e2..af56800d5 100644 --- a/src/os/win32/ngx_files.h +++ b/src/os/win32/ngx_files.h @@ -98,6 +98,9 @@ ssize_t ngx_write_fd(ngx_fd_t fd, void *buf, size_t size); #define ngx_write_fd_n "WriteFile()" +ssize_t ngx_write_console(ngx_fd_t fd, void *buf, size_t size); + + #define ngx_linefeed(p) *p++ = CR; *p++ = LF; #define NGX_LINEFEED_SIZE 2