#define wrbuf_buf(b) ((b)->buf)
/** \brief returns WRBUF content as C-string
- \param b WRBUF
+ \param b WRBUF (may not be NULL)
\returns C-string
*/
YAZ_EXPORT const char *wrbuf_cstr(WRBUF b);
+/** \brief returns WRBUF content as C-string or NULL
+ \param b WRBUF
+ \returns C-string or NULL
+
+ This function returns NULL if either b is NULL or length of buffer is 0
+*/
+YAZ_EXPORT
+const char *wrbuf_cstr_null(WRBUF b);
+
#define wrbuf_putc(b, c) \
((void) ((b)->pos >= (b)->size ? wrbuf_grow(b, 1) : 0), \
(b)->buf[(b)->pos++] = (c), 0)
return b->buf;
}
+const char *wrbuf_cstr_null(WRBUF b)
+{
+ if (!b || b->pos == 0)
+ return 0;
+ assert(b->pos < b->size);
+ b->buf[b->pos] = '\0';
+ return b->buf;
+}
+
void wrbuf_cut_right(WRBUF b, size_t no_to_remove)
{
if (no_to_remove > b->pos)