diff options
Diffstat (limited to 'lib.h')
-rw-r--r-- | lib.h | 10 |
1 files changed, 10 insertions, 0 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; @@ -46,4 +48,12 @@ 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 |