Fixes.
[apps/pfixtools.git] / common / buffer.h
index 24bc590..c6c11c6 100644 (file)
 #include <stdarg.h>
 #include "mem.h"
 #include "str.h"
+#include "array.h"
 
-typedef struct buffer_t {
-    char *data;
-    ssize_t len;
-    ssize_t size;
-} buffer_t;
+typedef A(char) buffer_t;
 
 #define BUFFER_INIT {NULL, 0, 0}
 
@@ -66,8 +63,9 @@ static inline char *buffer_unwrap(buffer_t **buf) {
     return res;
 }
 
+#define buffer_resize(buffer, newsize)                                         \
+  array_ensure_exact_capacity(*(buffer), (newsize) + 1)
 
-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) {