Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Avoid conflicting with HTSlib's kstring.c functions
Make ksprintf() static inline in kstring.h, so that it (like the other
bwa/kstring.h functions) won't conflict with similar HTSlib functions.
Instead implement it and kvsprintf() in terms of a new bwa_kvsprintf()
function. Fixes samtools/htslib#693.
  • Loading branch information
jmarshall committed Mar 18, 2024
commit b52164f265af00ac1aea78e0288ea5d7703d19af
12 changes: 5 additions & 7 deletions kstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@
# include "malloc_wrap.h"
#endif

int ksprintf(kstring_t *s, const char *fmt, ...)
int bwa_kvsprintf(kstring_t *s, const char *fmt, va_list ap)
{
va_list ap;
va_list ap2;
int l;
va_start(ap, fmt);
va_copy(ap2, ap);
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);
l = vsnprintf(s->s + s->l, s->m - s->l, fmt, ap2);
}
va_end(ap);
va_end(ap2);
s->l += l;
return l;
}
Expand Down
18 changes: 17 additions & 1 deletion kstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <stdlib.h>
#include <string.h>
#include <stdarg.h>

#ifdef USE_MALLOC_WRAPPERS
# include "malloc_wrap.h"
Expand Down Expand Up @@ -110,6 +111,21 @@ static inline int kputl(long c, kstring_t *s)
return 0;
}

int ksprintf(kstring_t *s, const char *fmt, ...);
int bwa_kvsprintf(kstring_t *s, const char *fmt, va_list ap);

static inline int ksprintf(kstring_t *s, const char *fmt, ...)
{
va_list ap;
int l;
va_start(ap, fmt);
l = bwa_kvsprintf(s, fmt, ap);
va_end(ap);
return l;
}

static inline int kvsprintf(kstring_t *s, const char *fmt, va_list ap)
{
return bwa_kvsprintf(s, fmt, ap);
}

#endif