Now it does not mess with the pos. Still not 100% safe, can have
a race condition when reallocating the buf, if it needs room for
the terminating null byte.
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <assert.h>
#include <yaz/wrbuf.h>
#include <yaz/snprintf.h>
const char *wrbuf_cstr(WRBUF b)
{
- wrbuf_putc(b, '\0'); /* add '\0' */
- (b->pos)--; /* don't include '\0' in count */
+ if (b->pos >= b->size)
+ wrbuf_grow(b, 1);
+ b->buf[b->pos] = '\0';
return b->buf;
}