summaryrefslogtreecommitdiff
path: root/src/str.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/str.c')
-rw-r--r--src/str.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/str.c b/src/str.c
index 2ad46aa..25b267a 100644
--- a/src/str.c
+++ b/src/str.c
@@ -1,5 +1,25 @@
#include "../include/al/str.h"
+static __thread char printbuf[24];
+static __thread str printstr = {
+ .length = 0,
+ .alloc = 0,
+ .data = NULL
+};
+
+#define DEFINE_PRINT_FUNC(type, fmt) \
+ str *al_print_##type(type n) \
+ { \
+ s32 ret = al_snprintf(printbuf, sizeof(printbuf), fmt, n); \
+ al_assert(ret > 0 && (size_t)ret < sizeof(printbuf)); \
+ printstr.length = ret; \
+ printstr.data = printbuf; \
+ return &printstr; \
+ }
+
+DEFINE_PRINT_FUNC(u32, "%u")
+DEFINE_PRINT_FUNC(s32, "%d")
+
// https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/stdlib/strtol.c;h=09d4333ed05f497ec00b7192204644349441e58d;hb=HEAD#l130
s64 al_str_to_long(str *s, u32 base, bool *error)
{