diff --git a/gebs.h b/gebs.h index 8b75dbd..195742f 100644 --- a/gebs.h +++ b/gebs.h @@ -24,6 +24,7 @@ #include #include #include +#include #if GEBS_PLATFORM == GEBS_PLATFORM_POSIX # include @@ -262,13 +263,7 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv, extern Gebs_Arena *gebs_scratch_arena; -#define gebs_fmt(fmt, ...) \ -({ \ - size_t __size = snprintf(NULL, 0, (fmt), ##__VA_ARGS__); \ - char *__buf = gebs_malloc(gebs_scratch_arena, __size+1); \ - sprintf(__buf, (fmt), ##__VA_ARGS__); \ - __buf; \ -}) +char *gebs_fmt(const char *fmt, ...); #ifdef GEBS_IMPLEMENTATION @@ -468,6 +463,22 @@ void gebs_scratch_areana_free(void) gebs_arena_destroy(gebs_scratch_arena); } +char *gebs_fmt(const char *fmt, ...) +{ + va_list list; + va_start(list, fmt); + + va_list list_copy; + va_copy(list_copy, list); + size_t size = vsnprintf(NULL, 0, fmt, list_copy); + va_end(list_copy); + + char *buf = gebs_malloc(gebs_scratch_arena, size+1); + vsprintf(buf, fmt, list); + va_end(list); + return buf; +} + // ---------------------------------------------------------------------------- // Filesystem operations // ----------------------------------------------------------------------------