-struct buf {
- char *p;
- size_t n, sz;
-};
-#define BUF_INIT { 0, 0, 0 }
-#define BUF_REWIND(b) do { (b)->n = 0; } while (0)
-#define BUF_FREE(b) do { \
- buf *_b = (b); \
- free(_b->p); _b->p = 0; _b->n = _b->sz = 0; \
-} while (0)
-#define BUF_PUTC(b, ch) do { \
- struct buf *_b = (b); \
- if (_b->n >= _b->sz) { \
- _b->sz = _b->sz ? 2*_b->sz : 32; \
- _b->p = realloc(_b->p, _b->sz); \
- if (!_b->p) bail("out of memory allocating %zu bytes", _b->sz); \
- } \
- _b->p[_b->n] = (ch); \
-} while (0)
-