https://github.com/lh3/bwa
Tip revision: 139f68fc4c3747813783a488aef2adc86626b01b authored by Heng Li on 22 September 2022, 23:52:12 UTC
Merge pull request #367 from martin-g/github-actions-linux-aarch64
Merge pull request #367 from martin-g/github-actions-linux-aarch64
Tip revision: 139f68f
kstring.c
#include <stdarg.h>
#include <stdio.h>
#include "kstring.h"
#ifdef USE_MALLOC_WRAPPERS
# include "malloc_wrap.h"
#endif
int ksprintf(kstring_t *s, const char *fmt, ...)
{
va_list ap;
int l;
va_start(ap, fmt);
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
va_end(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);
va_start(ap, fmt);
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap);
}
va_end(ap);
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