-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathngx_string.c
67 lines (55 loc) · 980 Bytes
/
ngx_string.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdarg.h>
#include <stdio.h>
/**
* 需要可变参数支持,调用放在va_start()与va_end()之间
*
* va_start(args, fmt);
* p = ngx_vslprintf(p, last, fmt, args);
* va_end(args);
*/
char *
ngx_vslprintf(char *buf, char *last, const char *fmt, va_list args)
{
char *p;
int d, i;
while (*fmt && buf < last) {
if (*fmt == '%') {
fmt++;
switch (*fmt) {
case 's':
p = va_arg(args, char *);
while (*p && buf < last) {
//*buf++ = *p++;
*buf = *p;
buf++;
p++;
}
fmt++;
continue;
case 'c':
d = va_arg(args, int);
*buf++ = (char) (d & 0xff);
fmt++;
continue;
case 'd':
d = va_arg(args, int);
i = snprintf(buf, last - buf, "%d", d);
buf += i;
fmt++;
continue;
default:
//*buf++ = *fmt++;
*buf = *fmt;
buf++;
fmt++;
continue;
}
} else {
//*buf++ = *fmt++;
*buf = *fmt;
buf++;
fmt++;
}
}
return buf;
}