File: kstring.c

package info (click to toggle)
bwa 0.7.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,196 kB
  • sloc: ansic: 13,822; javascript: 877; perl: 190; sh: 100; makefile: 99
file content (37 lines) | stat: -rw-r--r-- 683 bytes parent folder | download | duplicates (2)
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
#include <stdarg.h>
#include <stdio.h>
#include "kstring.h"

#ifdef USE_MALLOC_WRAPPERS
#  include "malloc_wrap.h"
#endif

int bwa_kvsprintf(kstring_t *s, const char *fmt, va_list ap)
{
	va_list ap2;
	int l;
	va_copy(ap2, ap);
	l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
	if (l + 1 > s->m - s->l) {
		s->m = s->l + l + 2;
		kroundup32(s->m);
		s->s = (char*)realloc(s->s, s->m);
		l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap2);
	}
	va_end(ap2);
	s->l += l;
	return l;
}

#ifdef KSTRING_MAIN
#include <stdio.h>
int main()
{
	kstring_t *s;
	s = (kstring_t*)calloc(1, sizeof(kstring_t));
	ksprintf(s, "abcdefg: %d", 100);
	printf("%s\n", s->s);
	free(s);
	return 0;
}
#endif