blob: ed2d8be2c4fc41390c9912d745c240db9df43a0d (
plain)
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
|
#include <stdarg.h>
#include <stdint.h>
enum TYPE {
TYPE_INT = 1,
TYPE_UINT = 2,
TYPE_HEX = 3,
TYPE_STRING = 4
};
int vsprintf(char *str, char *fmt, va_list ap) {
char *s;
char *start = str;
uint8_t type;
while(*fmt) {
if(*fmt != '%') {
*str++ = *fmt++;
continue;
}
fmt++;
while(1) {
switch(*fmt) {
case 's':
if(type)
goto done;
type = TYPE_STRING;
break;
default:
goto done;
break;
}
fmt++;
}
done:
switch(type) {
case TYPE_STRING:
s = va_arg(ap, char*);
while(*s)
*str++ = *s++;
break;
}
}
*str = 0;
return (str - start);
}
|