diff options
Diffstat (limited to 'lib.h')
-rw-r--r-- | lib.h | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -26,6 +26,8 @@ char *fread_all(FILE *fp); void print_error(const char *handle, size_t row, size_t column, const char *reason); +#define SIZE_FMT(FMT, ...) (snprintf(NULL, 0, (FMT), __VA_ARGS__)) + typedef struct Buffer { const char *name; @@ -41,9 +43,17 @@ typedef struct u8 *data; } vec_t; -void vec_append(vec_t *vec, void *ptr, u64 size); +void vec_append(vec_t *vec, const void *const ptr, u64 size); void vec_ensure(vec_t *vec, u64 abs_size); void vec_ensure_free(vec_t *vec, u64 rel_size); void vec_free(vec_t *vec); +#define vec_append_fmt(VEC, FMT, ...) \ + do \ + { \ + char f[SIZE_FMT(FMT, __VA_ARGS__) + 1]; \ + snprintf(f, sizeof(f), (FMT), __VA_ARGS__); \ + vec_append((VEC), f, sizeof(f) - 1); \ + } while (0) + #endif |