Mercurial > hg > nginx-ranges
comparison src/core/ngx_string.c @ 4:4b2dafa26fe2 NGINX_0_1_2
nginx 0.1.2
*) Feature: the --user=USER, --group=GROUP, and --with-ld-opt=OPTIONS
options in configure.
*) Feature: the server_name directive supports *.domain.tld.
*) Bugfix: the portability improvements.
*) Bugfix: if configuration file was set in command line, the
reconfiguration was impossible; bug appeared in 0.1.1.
*) Bugfix: proxy module may get caught in an endless loop when sendfile
is not used.
*) Bugfix: with sendfile the response was not recoded according to the
charset module directives; bug appeared in 0.1.1.
*) Bugfix: very seldom bug in the kqueue processing.
*) Bugfix: the gzip module compressed the proxied responses that was
already compressed.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Thu, 21 Oct 2004 00:00:00 +0400 |
parents | cc9f381affaa |
children | 80ba094c6b3e |
comparison
equal
deleted
inserted
replaced
3:8beaf7b3241f | 4:4b2dafa26fe2 |
---|---|
26 | 26 |
27 return dst; | 27 return dst; |
28 } | 28 } |
29 | 29 |
30 | 30 |
31 /* | |
32 * supported formats: | |
33 * %[0][width]O off_t | |
34 * %[0][width]T time_t | |
35 * %[0][width]S ssize_t | |
36 * %[0][width]uS size_t | |
37 * %[0][width]uxS size_t in hex | |
38 * %[0][width]l long | |
39 * %[0][width]d int | |
40 * %[0][width]i ngx_int_t | |
41 * %[0][width]ui ngx_uint_t | |
42 * %[0][width]uxi ngx_uint_t in hex | |
43 * %s null-terminated string | |
44 * %% % | |
45 * | |
46 */ | |
47 | |
48 u_char *ngx_sprintf(u_char *buf, char *fmt, ...) | |
49 { | |
50 u_char *p, c, temp[NGX_MAX_INT_LEN]; | |
51 int d; | |
52 long l; | |
53 off_t offset; | |
54 size_t size, len; | |
55 ssize_t ssize; | |
56 time_t sec; | |
57 va_list arg; | |
58 ngx_int_t i; | |
59 ngx_uint_t ui, zero, width, sign, hexadecimal; | |
60 static u_char hex[] = "0123456789abcdef"; | |
61 | |
62 va_start(arg, fmt); | |
63 | |
64 while (*fmt) { | |
65 if (*fmt == '%') { | |
66 | |
67 zero = (*++fmt == '0') ? 1 : 0; | |
68 width = 0; | |
69 sign = 1; | |
70 hexadecimal = 0; | |
71 | |
72 p = temp + NGX_MAX_INT_LEN; | |
73 | |
74 while (*fmt >= '0' && *fmt <= '9') { | |
75 width = width * 10 + *fmt++ - '0'; | |
76 } | |
77 | |
78 | |
79 for ( ;; ) { | |
80 switch (*fmt) { | |
81 | |
82 case 'u': | |
83 sign = 0; | |
84 fmt++; | |
85 continue; | |
86 | |
87 case 'x': | |
88 hexadecimal = 1; | |
89 fmt++; | |
90 continue; | |
91 | |
92 default: | |
93 break; | |
94 } | |
95 | |
96 break; | |
97 } | |
98 | |
99 | |
100 switch (*fmt) { | |
101 | |
102 case 'O': | |
103 offset = va_arg(arg, off_t); | |
104 | |
105 if (offset < 0) { | |
106 *buf++ = '-'; | |
107 offset = -offset; | |
108 } | |
109 | |
110 do { | |
111 *--p = (u_char) (offset % 10 + '0'); | |
112 } while (offset /= 10); | |
113 | |
114 break; | |
115 | |
116 case 'T': | |
117 sec = va_arg(arg, time_t); | |
118 | |
119 if (sec < 0) { | |
120 *buf++ = '-'; | |
121 sec = -sec; | |
122 } | |
123 | |
124 do { | |
125 *--p = (u_char) (sec % 10 + '0'); | |
126 } while (sec /= 10); | |
127 | |
128 break; | |
129 | |
130 case 'S': | |
131 if (sign) { | |
132 ssize = va_arg(arg, ssize_t); | |
133 | |
134 if (ssize < 0) { | |
135 *buf++ = '-'; | |
136 size = (size_t) -ssize; | |
137 | |
138 } else { | |
139 size = (size_t) ssize; | |
140 } | |
141 | |
142 } else { | |
143 size = va_arg(arg, size_t); | |
144 } | |
145 | |
146 if (hexadecimal) { | |
147 do { | |
148 *--p = hex[size & 0xf]; | |
149 } while (size >>= 4); | |
150 | |
151 } else { | |
152 do { | |
153 *--p = (u_char) (size % 10 + '0'); | |
154 } while (size /= 10); | |
155 } | |
156 | |
157 break; | |
158 | |
159 case 'l': | |
160 l = va_arg(arg, long); | |
161 | |
162 if (l < 0) { | |
163 *buf++ = '-'; | |
164 l = -l; | |
165 } | |
166 | |
167 do { | |
168 *--p = (u_char) (l % 10 + '0'); | |
169 } while (l /= 10); | |
170 | |
171 break; | |
172 | |
173 case 'd': | |
174 d = va_arg(arg, int); | |
175 | |
176 if (d < 0) { | |
177 *buf++ = '-'; | |
178 d = -d; | |
179 } | |
180 | |
181 do { | |
182 *--p = (u_char) (d % 10 + '0'); | |
183 } while (d /= 10); | |
184 | |
185 break; | |
186 | |
187 case 'i': | |
188 if (sign) { | |
189 i = va_arg(arg, ngx_int_t); | |
190 | |
191 if (i < 0) { | |
192 *buf++ = '-'; | |
193 ui = (ngx_uint_t) -i; | |
194 | |
195 } else { | |
196 ui = (ngx_uint_t) i; | |
197 } | |
198 | |
199 } else { | |
200 ui = va_arg(arg, ngx_uint_t); | |
201 } | |
202 | |
203 if (hexadecimal) { | |
204 do { | |
205 *--p = hex[ui & 0xf]; | |
206 } while (ui >>= 4); | |
207 | |
208 } else { | |
209 do { | |
210 *--p = (u_char) (ui % 10 + '0'); | |
211 } while (ui /= 10); | |
212 } | |
213 | |
214 break; | |
215 | |
216 case 's': | |
217 p = va_arg(arg, u_char *); | |
218 | |
219 while (*p) { | |
220 *buf++ = *p++; | |
221 } | |
222 fmt++; | |
223 | |
224 continue; | |
225 | |
226 case '%': | |
227 *buf++ = '%'; | |
228 fmt++; | |
229 | |
230 continue; | |
231 | |
232 default: | |
233 *buf++ = *fmt++; | |
234 | |
235 continue; | |
236 } | |
237 | |
238 len = (temp + NGX_MAX_INT_LEN) - p; | |
239 | |
240 c = (u_char) (zero ? '0' : ' '); | |
241 | |
242 while (len++ < width) { | |
243 *buf++ = c; | |
244 } | |
245 | |
246 buf = ngx_cpymem(buf, p, ((temp + NGX_MAX_INT_LEN) - p)); | |
247 | |
248 fmt++; | |
249 | |
250 } else { | |
251 *buf++ = *fmt++; | |
252 } | |
253 } | |
254 | |
255 va_end(arg); | |
256 | |
257 *buf = '\0'; | |
258 | |
259 return buf; | |
260 } | |
261 | |
262 | |
31 ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) | 263 ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n) |
32 { | 264 { |
33 if (n == 0) { | 265 if (n == 0) { |
34 return 0; | 266 return 0; |
35 } | 267 } |
37 n--; | 269 n--; |
38 | 270 |
39 for ( ;; ) { | 271 for ( ;; ) { |
40 if (s1[n] != s2[n]) { | 272 if (s1[n] != s2[n]) { |
41 return s1[n] - s2[n]; | 273 return s1[n] - s2[n]; |
274 } | |
275 | |
276 if (n == 0) { | |
277 return 0; | |
278 } | |
279 | |
280 n--; | |
281 } | |
282 } | |
283 | |
284 | |
285 ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) | |
286 { | |
287 u_char c1, c2; | |
288 | |
289 if (n == 0) { | |
290 return 0; | |
291 } | |
292 | |
293 n--; | |
294 | |
295 for ( ;; ) { | |
296 c1 = s1[n]; | |
297 if (c1 >= 'a' && c1 <= 'z') { | |
298 c1 -= 'a' - 'A'; | |
299 } | |
300 | |
301 c2 = s2[n]; | |
302 if (c2 >= 'a' && c2 <= 'z') { | |
303 c2 -= 'a' - 'A'; | |
304 } | |
305 | |
306 if (c1 != c2) { | |
307 return c1 - c2; | |
42 } | 308 } |
43 | 309 |
44 if (n == 0) { | 310 if (n == 0) { |
45 return 0; | 311 return 0; |
46 } | 312 } |