diff options
author | Igor Sysoev <igor@sysoev.ru> | 2009-04-27 17:17:33 +0400 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2009-04-27 17:17:33 +0400 |
commit | f67e0a4050c7d180123ad8bd473275cf40a7e483 (patch) | |
tree | 601f776b08e95b6f51ffe9b8226873a4a2ceb2e7 /src/core/ngx_log.c | |
parent | e1c9746e371d387f4166fe99d65fd94a3f27c260 (diff) |
ngx_log_errno()
Diffstat (limited to 'src/core/ngx_log.c')
-rw-r--r-- | src/core/ngx_log.c | 70 |
1 files changed, 28 insertions, 42 deletions
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c index 90b437a13..3fb697b7d 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -126,29 +126,7 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, #endif if (err) { - - if (p > last - 50) { - - /* leave a space for an error code */ - - p = last - 50; - *p++ = '.'; - *p++ = '.'; - *p++ = '.'; - } - -#if (NGX_WIN32) - p = ngx_slprintf(p, last, ((unsigned) err < 0x80000000) - ? " (%d: " : " (%Xd: ", err); -#else - p = ngx_slprintf(p, last, " (%d: ", err); -#endif - - p = ngx_strerror_r(err, p, last - p); - - if (p < last) { - *p++ = ')'; - } + p = ngx_log_errno(p, last, err); } if (level != NGX_LOG_DEBUG && log->handler) { @@ -236,39 +214,47 @@ ngx_log_stderr(ngx_err_t err, const char *fmt, ...) p = ngx_vslprintf(errstr, last, fmt, args); va_end(args); - if (p > errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE) { - p = errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE; + if (err) { + p = ngx_log_errno(p, last, err); } - if (err) { + if (p > last - NGX_LINEFEED_SIZE) { + p = last - NGX_LINEFEED_SIZE; + } + + ngx_linefeed(p); - if (p > last - 50) { + (void) ngx_write_fd(ngx_stderr, errstr, p - errstr); +} - /* leave a space for an error code */ - p = last - 50; - *p++ = '.'; - *p++ = '.'; - *p++ = '.'; - } +u_char * +ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err) +{ + if (buf > last - 50) { + + /* leave a space for an error code */ + + buf = last - 50; + *buf++ = '.'; + *buf++ = '.'; + *buf++ = '.'; + } #if (NGX_WIN32) - p = ngx_slprintf(p, last, ((unsigned) err < 0x80000000) + buf = ngx_slprintf(buf, last, ((unsigned) err < 0x80000000) ? " (%d: " : " (%Xd: ", err); #else - p = ngx_slprintf(p, last, " (%d: ", err); + buf = ngx_slprintf(buf, last, " (%d: ", err); #endif - p = ngx_strerror_r(err, p, last - p); + buf = ngx_strerror_r(err, buf, last - buf); - if (p < last) { - *p++ = ')'; - } + if (buf < last) { + *buf++ = ')'; } - ngx_linefeed(p); - - (void) ngx_write_fd(ngx_stderr, errstr, p - errstr); + return buf; } |