comparison src/core/ngx_string.c @ 2763:819bea4e964e

ngx_vslprintf(), ngx_slprintf()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 27 Apr 2009 12:51:33 +0000
parents 82e3946062be
children 41e7d9153967 4b5cf483c6a8
comparison
equal deleted inserted replaced
2762:0cc1af11760d 2763:819bea4e964e
97 { 97 {
98 u_char *p; 98 u_char *p;
99 va_list args; 99 va_list args;
100 100
101 va_start(args, fmt); 101 va_start(args, fmt);
102 p = ngx_vsnprintf(buf, /* STUB */ 65536, fmt, args); 102 p = ngx_vslprintf(buf, (void *) -1, fmt, args);
103 va_end(args); 103 va_end(args);
104 104
105 return p; 105 return p;
106 } 106 }
107 107
111 { 111 {
112 u_char *p; 112 u_char *p;
113 va_list args; 113 va_list args;
114 114
115 va_start(args, fmt); 115 va_start(args, fmt);
116 p = ngx_vsnprintf(buf, max, fmt, args); 116 p = ngx_vslprintf(buf, buf + max, fmt, args);
117 va_end(args); 117 va_end(args);
118 118
119 return p; 119 return p;
120 } 120 }
121 121
122 122
123 u_char * ngx_cdecl
124 ngx_slprintf(u_char *buf, u_char *last, const char *fmt, ...)
125 {
126 u_char *p;
127 va_list args;
128
129 va_start(args, fmt);
130 p = ngx_vslprintf(buf, last, fmt, args);
131 va_end(args);
132
133 return p;
134 }
135
136
123 u_char * 137 u_char *
124 ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args) 138 ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args)
125 { 139 {
126 u_char *p, zero, *last; 140 u_char *p, zero;
127 int d; 141 int d;
128 float f, scale; 142 float f, scale;
129 size_t len, slen; 143 size_t len, slen;
130 int64_t i64; 144 int64_t i64;
131 uint64_t ui64; 145 uint64_t ui64;
132 ngx_msec_t ms; 146 ngx_msec_t ms;
133 ngx_uint_t width, sign, hex, max_width, frac_width, i; 147 ngx_uint_t width, sign, hex, max_width, frac_width, i;
134 ngx_str_t *v; 148 ngx_str_t *v;
135 ngx_variable_value_t *vv; 149 ngx_variable_value_t *vv;
136
137 if (max == 0) {
138 return buf;
139 }
140
141 last = buf + max;
142 150
143 while (*fmt && buf < last) { 151 while (*fmt && buf < last) {
144 152
145 /* 153 /*
146 * "buf < last" means that we could copy at least one character: 154 * "buf < last" means that we could copy at least one character: