aboutsummaryrefslogtreecommitdiff
path: root/lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib.h')
-rw-r--r--lib.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib.h b/lib.h
index c58d425..9d964f7 100644
--- a/lib.h
+++ b/lib.h
@@ -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