n->buf = 0;
n->size = 0;
n->pos = 0;
+ wrbuf_grow(n, 1);
return n;
}
togrow = b->size;
if (togrow < minsize)
togrow = minsize;
- if (b->size && !(b->buf =(char *)xrealloc(b->buf, b->size += togrow)))
- abort();
- else if (!b->size && !(b->buf = (char *)xmalloc(b->size = togrow)))
+ b->buf = (char *) xrealloc(b->buf, 1 + (b->size += togrow));
+ if (!b->buf)
abort();
return 0;
}
const char *wrbuf_cstr(WRBUF b)
{
- if (b->pos >= b->size)
- wrbuf_grow(b, 1);
+ assert(b && b->pos <= b->size);
+ b->buf[b->pos] = '\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;
}