Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 1 | /* Capstone Disassembler Engine */ |
| 2 | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013> */ |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <stdarg.h> |
| 6 | #include <stdio.h> |
| 7 | |
| 8 | #include "SStream.h" |
Nguyen Anh Quynh | edeeb04 | 2014-01-15 20:44:03 +0800 | [diff] [blame^] | 9 | #include "cs_priv.h" |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 10 | |
| 11 | void SStream_Init(SStream *ss) |
| 12 | { |
| 13 | ss->index = 0; |
| 14 | ss->buffer[0] = '\0'; |
| 15 | } |
| 16 | |
| 17 | void SStream_concat(SStream *ss, const char *fmt, ...) |
| 18 | { |
| 19 | va_list ap; |
| 20 | |
| 21 | va_start(ap, fmt); |
Nguyen Anh Quynh | edeeb04 | 2014-01-15 20:44:03 +0800 | [diff] [blame^] | 22 | int ret = cs_vsnprintf(ss->buffer + ss->index, sizeof(ss->buffer) - (ss->index + 1), fmt, ap); |
Nguyen Anh Quynh | 26ee41a | 2013-11-27 12:11:31 +0800 | [diff] [blame] | 23 | va_end(ap); |
| 24 | ss->index += ret; |
| 25 | } |
| 26 | |
| 27 | /* |
| 28 | int main() |
| 29 | { |
| 30 | SStream ss; |
| 31 | int64_t i; |
| 32 | |
| 33 | SStream_Init(&ss); |
| 34 | |
| 35 | SStream_concat(&ss, "hello "); |
| 36 | SStream_concat(&ss, "%d - 0x%x", 200, 16); |
| 37 | |
| 38 | i = 123; |
| 39 | SStream_concat(&ss, " + %ld", i); |
| 40 | SStream_concat(&ss, "%s", "haaaaa"); |
| 41 | |
| 42 | printf("%s\n", ss.buffer); |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | */ |