blob: 88fe9f689d72686a56e0e09d374f4937b943c13d [file] [log] [blame]
Nguyen Anh Quynh6023ef72014-04-29 11:21:04 +08001/* Capstone Disassembly Engine */
2/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08003
4#include <stdint.h>
5#include <stdarg.h>
6#include <stdio.h>
Nguyen Anh Quynhb76233c2014-06-04 18:31:02 +08007#include <string.h>
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +08008
9#include "SStream.h"
Nguyen Anh Quynhedeeb042014-01-15 20:44:03 +080010#include "cs_priv.h"
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080011
12void SStream_Init(SStream *ss)
13{
14 ss->index = 0;
15 ss->buffer[0] = '\0';
16}
17
Nguyen Anh Quynhb76233c2014-06-04 18:31:02 +080018void SStream_concat0(SStream *ss, char *s)
19{
20#ifndef CAPSTONE_DIET
21 strcpy(ss->buffer + ss->index, s);
22 ss->index += strlen(s);
23#endif
24}
25
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080026void SStream_concat(SStream *ss, const char *fmt, ...)
27{
Nguyen Anh Quynhfc83a432014-02-22 23:26:27 +080028#ifndef CAPSTONE_DIET
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080029 va_list ap;
Nguyen Anh Quynhbb0744d2014-05-12 13:41:49 +080030 int ret;
31
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080032 va_start(ap, fmt);
Axel 0vercl0k Souchet779d4c72014-05-08 23:44:49 +010033 ret = cs_vsnprintf(ss->buffer + ss->index, sizeof(ss->buffer) - (ss->index + 1), fmt, ap);
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080034 va_end(ap);
35 ss->index += ret;
Nguyen Anh Quynhfc83a432014-02-22 23:26:27 +080036#endif
Nguyen Anh Quynh26ee41a2013-11-27 12:11:31 +080037}
38
39/*
40 int main()
41 {
42 SStream ss;
43 int64_t i;
44
45 SStream_Init(&ss);
46
47 SStream_concat(&ss, "hello ");
48 SStream_concat(&ss, "%d - 0x%x", 200, 16);
49
50 i = 123;
51 SStream_concat(&ss, " + %ld", i);
52 SStream_concat(&ss, "%s", "haaaaa");
53
54 printf("%s\n", ss.buffer);
55
56 return 0;
57 }
58 */