annotate pyPRADA_1.2/tools/bwa-0.5.7-mh/kstring.c @ 0:acc2ca1a3ba4

Uploaded
author siyuan
date Thu, 20 Feb 2014 00:44:58 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
1 #include <stdarg.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
2 #include <stdio.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
3 #include "kstring.h"
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
4
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
5 int ksprintf(kstring_t *s, const char *fmt, ...)
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
6 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
7 va_list ap;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
8 int l;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
9 va_start(ap, fmt);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
10 l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
11 va_end(ap);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
12 if (l + 1 > s->m - s->l) {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
13 s->m = s->l + l + 2;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
14 kroundup32(s->m);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
15 s->s = (char*)realloc(s->s, s->m);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
16 va_start(ap, fmt);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
17 l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
18 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
19 va_end(ap);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
20 s->l += l;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
21 return l;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
22 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
23
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
24 #ifdef KSTRING_MAIN
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
25 #include <stdio.h>
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
26 int main()
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
27 {
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
28 kstring_t *s;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
29 s = (kstring_t*)calloc(1, sizeof(kstring_t));
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
30 ksprintf(s, "abcdefg: %d", 100);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
31 printf("%s\n", s->s);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
32 free(s);
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
33 return 0;
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
34 }
acc2ca1a3ba4 Uploaded
siyuan
parents:
diff changeset
35 #endif