// SPDX-License-Identifier: MIT #pragma once #include "stdint.h" #include "util.h" struct dbuf { size_t capacity; size_t len; u8 *buf; }; inline struct dbuf _db_new(size_t capacity) { struct dbuf db; db.capacity = capacity; db.len = 0; db.buf = xmalloc(capacity); return db; } // Unfortunately, pre-C99 we can't have an initializer list with xmalloc #define DB_INIT(name, capacity) \ struct dbuf name = _db_new(capacity) void db_init(struct dbuf* db, size_t capacity); void db_extend(struct dbuf* db, u8* buf, size_t bufsize); void db_printf(struct dbuf* db, const char* fmt, ...); void db_destroy(struct dbuf* db); void db_clear(struct dbuf* db);