Mercurial > hg > nginx-vendor-current
diff src/core/ngx_string.c @ 42:41ccba1aba45 NGINX_0_1_21
nginx 0.1.21
*) Bugfix: the ngx_http_stub_status_module showed incorrect statistics
if "rtsig" method was used or if several worker process ran on SMP.
*) Bugfix: nginx could not be built by the icc compiler on Linux or if
the zlib-1.2.x library was building from sources.
*) Bugfix: nginx could not be built on NetBSD 2.0.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 22 Feb 2005 00:00:00 +0300 |
parents | aab2ea7c0458 |
children | 4989c3d25945 |
line wrap: on
line diff
--- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -8,7 +8,8 @@ #include <ngx_core.h> -u_char *ngx_cpystrn(u_char *dst, u_char *src, size_t n) +u_char * +ngx_cpystrn(u_char *dst, u_char *src, size_t n) { if (n == 0) { return dst; @@ -28,7 +29,8 @@ u_char *ngx_cpystrn(u_char *dst, u_char } -u_char *ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src) +u_char * +ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src) { u_char *dst; @@ -52,6 +54,7 @@ u_char *ngx_pstrdup(ngx_pool_t *pool, ng * %[0][width|m][u][x|X]i ngx_int_t/ngx_uint_t * %[0][width][u][x|X]D int32_t/uint32_t * %[0][width][u][x|X]L int64_t/uint64_t + * %[0][width|m][u][x|X]A ngx_atomic_int_t * %P ngx_pid_t * %r rlim_t * %p pointer @@ -63,7 +66,6 @@ u_char *ngx_pstrdup(ngx_pool_t *pool, ng * * TODO: * %M ngx_msec_t - * %A ngx_atomic_t * * reserved: * %t ptrdiff_t @@ -72,7 +74,8 @@ u_char *ngx_pstrdup(ngx_pool_t *pool, ng */ -u_char *ngx_sprintf(u_char *buf, const char *fmt, ...) +u_char * +ngx_sprintf(u_char *buf, const char *fmt, ...) { u_char *p; va_list args; @@ -85,7 +88,8 @@ u_char *ngx_sprintf(u_char *buf, const c } -u_char *ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...) +u_char * +ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...) { u_char *p; va_list args; @@ -98,12 +102,13 @@ u_char *ngx_snprintf(u_char *buf, size_t } -u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) +u_char * +ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) { u_char *p, zero, *last, temp[NGX_INT64_LEN + 1]; /* * really we need temp[NGX_INT64_LEN] only, - * but icc shows the warning + * but icc issues the warning */ int d; size_t len; @@ -111,7 +116,7 @@ u_char *ngx_vsnprintf(u_char *buf, size_ int64_t i64; uint64_t ui64; ngx_str_t *s; - ngx_uint_t width, sign, hexadecimal; + ngx_uint_t width, sign, hexadecimal, max_width; static u_char hex[] = "0123456789abcdef"; static u_char HEX[] = "0123456789ABCDEF"; @@ -137,6 +142,7 @@ u_char *ngx_vsnprintf(u_char *buf, size_ width = 0; sign = 1; hexadecimal = 0; + max_width = 0; p = temp + NGX_INT64_LEN; @@ -154,7 +160,7 @@ u_char *ngx_vsnprintf(u_char *buf, size_ continue; case 'm': - width = NGX_INT_T_LEN; + max_width = 1; fmt++; continue; @@ -228,6 +234,11 @@ u_char *ngx_vsnprintf(u_char *buf, size_ } else { ui64 = (uint64_t) va_arg(args, ngx_uint_t); } + + if (max_width) { + width = NGX_INT_T_LEN; + } + break; case 'd': @@ -262,6 +273,19 @@ u_char *ngx_vsnprintf(u_char *buf, size_ } break; + case 'A': + if (sign) { + i64 = (int64_t) va_arg(args, ngx_atomic_int_t); + } else { + ui64 = (uint64_t) va_arg(args, ngx_atomic_int_t); + } + + if (max_width) { + width = NGX_ATOMIC_T_LEN; + } + + break; + #if !(NGX_WIN32) case 'r': i64 = (int64_t) va_arg(args, rlim_t); @@ -334,13 +358,15 @@ u_char *ngx_vsnprintf(u_char *buf, size_ * To divide 64-bit number and to find the remainder * on the x86 platform gcc and icc call the libc functions * [u]divdi3() and [u]moddi3(), they call another function - * in return. On FreeBSD it is the qdivrem() function, + * in its turn. On FreeBSD it is the qdivrem() function, * its source code is about 170 lines of the code. * The glibc counterpart is about 150 lines of the code. * - * For 32-bit numbers gcc and icc use the inlined - * multiplication and shifts. For example, unsigned - * "i32 / 10" is compiled to "(i32 * 0xCCCCCCCD) >> 35". + * For 32-bit numbers and some divisors gcc and icc use + * the inlined multiplication and shifts. For example, + * unsigned "i32 / 10" is compiled to + * + * (i32 * 0xCCCCCCCD) >> 35 */ ui32 = (uint32_t) ui64; @@ -379,7 +405,8 @@ u_char *ngx_vsnprintf(u_char *buf, size_ } -ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) +ngx_int_t +ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) { if (n == 0) { return 0; @@ -401,7 +428,8 @@ ngx_int_t ngx_rstrncmp(u_char *s1, u_cha } -ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) +ngx_int_t +ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) { u_char c1, c2; @@ -435,7 +463,8 @@ ngx_int_t ngx_rstrncasecmp(u_char *s1, u } -ngx_int_t ngx_atoi(u_char *line, size_t n) +ngx_int_t +ngx_atoi(u_char *line, size_t n) { ngx_int_t value; @@ -460,7 +489,8 @@ ngx_int_t ngx_atoi(u_char *line, size_t } -ngx_int_t ngx_hextoi(u_char *line, size_t n) +ngx_int_t +ngx_hextoi(u_char *line, size_t n) { u_char ch; ngx_int_t value; @@ -499,7 +529,8 @@ ngx_int_t ngx_hextoi(u_char *line, size_ } -void ngx_md5_text(u_char *text, u_char *md5) +void +ngx_md5_text(u_char *text, u_char *md5) { int i; static u_char hex[] = "0123456789abcdef"; @@ -513,7 +544,8 @@ void ngx_md5_text(u_char *text, u_char * } -void ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src) +void +ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src) { u_char *d, *s; size_t len; @@ -553,7 +585,8 @@ void ngx_encode_base64(ngx_str_t *dst, n } -ngx_int_t ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src) +ngx_int_t +ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src) { size_t len; u_char *d, *s; @@ -616,19 +649,20 @@ ngx_int_t ngx_decode_base64(ngx_str_t *d } -uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type) +uintptr_t +ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type) { ngx_uint_t i, n; uint32_t *escape; static u_char hex[] = "0123456789abcdef"; - /* " ", "%", "?", %00-%1F, %7F-%FF */ + /* " ", "#", "%", "?", %00-%1F, %7F-%FF */ static uint32_t uri[] = { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ - 0x80000021, /* 1000 0000 0000 0000 0000 0000 0010 0001 */ + 0x80000029, /* 1000 0000 0000 0000 0000 0000 0010 1001 */ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ @@ -641,13 +675,13 @@ uintptr_t ngx_escape_uri(u_char *dst, u_ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ }; - /* " ", "%", "+", "?", %00-%1F, %7F-%FF */ + /* " ", "#", "%", "+", "?", %00-%1F, %7F-%FF */ static uint32_t args[] = { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ - 0x80000821, /* 1000 0000 0000 0000 0000 1000 0010 0001 */ + 0x80000829, /* 1000 0000 0000 0000 0000 1000 0010 1001 */ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */ @@ -666,7 +700,7 @@ uintptr_t ngx_escape_uri(u_char *dst, u_ { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */ - 0x80000021, /* 0000 0000 0000 0000 0000 0000 1010 0101 */ + 0x800000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */