diff options
| author | 2026-08-25 19:29:52 -0400 | |
|---|---|---|
| committer | 2026-08-25 19:29:52 -0400 | |
| commit | b617e3ccb25a0ac3c22f8c02722c8108b2f78d6e (patch) | |
| tree | 483c374801450fad4dde9b689d731e912e6dcacb /src | |
| parent | 20f9d23538811dde9ce8aea051408a05e178b6d4 (diff) | |
| download | libalabaster-b617e3ccb25a0ac3c22f8c02722c8108b2f78d6e.tar.gz libalabaster-b617e3ccb25a0ac3c22f8c02722c8108b2f78d6e.tar.bz2 libalabaster-b617e3ccb25a0ac3c22f8c02722c8108b2f78d6e.zip | |
str: Thread-local buffer for int to string
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src')
| -rw-r--r-- | src/str.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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) { |