+typedef struct buffer_t {
+ char *data;
+ ssize_t len;
+ ssize_t size;
+} buffer_t;
+
+DO_INIT(buffer_t, buffer);
+static inline void buffer_wipe(buffer_t *buf) {
+ p_delete(&buf->data);
+}
+DO_NEW(buffer_t, buffer);
+DO_DELETE(buffer_t, buffer);
+
+static inline char *buffer_unwrap(buffer_t **buf) {
+ char *res = (*buf)->data;
+ (*buf)->data = NULL;
+ buffer_delete(buf);
+ return res;
+}
+
+
+void buffer_resize(buffer_t *, ssize_t newsize);
+static inline void buffer_ensure(buffer_t *buf, ssize_t extra) {
+ assert (extra >= 0);
+ if (buf->len + extra >= buf->size) {
+ buffer_resize(buf, buf->len + extra);
+ }
+}
+static inline void buffer_extend(buffer_t *buf, ssize_t extra) {
+ buffer_ensure(buf, extra);
+ buf->len += extra;
+ buf->data[buf->len] = '\0';
+}
+static inline void buffer_extendch(buffer_t *buf, ssize_t extra, int c) {
+ buffer_ensure(buf, extra);
+ memset(buf->data + buf->len, c, extra);
+ buf->len += extra;
+ buf->data[buf->len] = '\0';
+}