From c455e7b67d2e55e6ed03e3449203d4e307f5a7dd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 13 Sep 2024 20:18:08 -0400 Subject: Rename builtins/ -> stdlib/ --- stdlib/util.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 stdlib/util.c (limited to 'stdlib/util.c') diff --git a/stdlib/util.c b/stdlib/util.c new file mode 100644 index 00000000..7749b22c --- /dev/null +++ b/stdlib/util.c @@ -0,0 +1,28 @@ +// Built-in utility functions +#include +#include +#include +#include +#include +#include + +#include "text.h" +#include "util.h" + +public bool USE_COLOR; + +__attribute__((format(printf, 1, 2))) +public char *heap_strf(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + char *tmp = NULL; + int len = vasprintf(&tmp, fmt, args); + if (len < 0) return NULL; + va_end(args); + char *ret = GC_strndup(tmp, (size_t)len); + free(tmp); + return ret; +} + +// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0 -- cgit v1.2.3