diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2023-03-28 06:50:55 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2023-03-28 06:50:55 +0200 |
commit | 2cb2ba5349679437457fe63566fab81fde669d76 (patch) | |
tree | 3b3e91477aa5504b73c5be19ff8113c1394fc4c7 | |
parent | 4126fa433baedc37c90f6984db5beb73d45ad3a6 (diff) | |
download | kit-2cb2ba5349679437457fe63566fab81fde669d76.zip |
Banbarian strings. 8 buffers.
-rw-r--r-- | include/kit.inl.h | 14 | ||||
-rw-r--r-- | source/kit/string_ref.h | 14 |
2 files changed, 18 insertions, 10 deletions
diff --git a/include/kit.inl.h b/include/kit.inl.h index 4c50c24..da2583d 100644 --- a/include/kit.inl.h +++ b/include/kit.inl.h @@ -326,15 +326,19 @@ static kit_str_t kit_str(ptrdiff_t const size, /* Make a barbarian string for C standard library functions. * Not thread safe. + * Use with caution. */ static char const *kit_make_bs(kit_str_t const s) { - static char buf[4096]; - ptrdiff_t n = s.size; + static char buf[8][4096]; + static int index = 0; + ptrdiff_t n = s.size; if (n > 4095) n = 4095; - memcpy(buf, s.values, n); - buf[n] = '\0'; - return buf; + memcpy(buf[index], s.values, n); + buf[index][n] = '\0'; + char const *result = buf[index]; + index = (index + 1) % 8; + return result; } #ifdef __GNUC__ diff --git a/source/kit/string_ref.h b/source/kit/string_ref.h index 6c89292..5584880 100644 --- a/source/kit/string_ref.h +++ b/source/kit/string_ref.h @@ -30,15 +30,19 @@ static kit_str_t kit_str(ptrdiff_t const size, /* Make a barbarian string for C standard library functions. * Not thread safe. + * Use with caution. */ static char const *kit_make_bs(kit_str_t const s) { - static char buf[4096]; - ptrdiff_t n = s.size; + static char buf[8][4096]; + static int index = 0; + ptrdiff_t n = s.size; if (n > 4095) n = 4095; - memcpy(buf, s.values, n); - buf[n] = '\0'; - return buf; + memcpy(buf[index], s.values, n); + buf[index][n] = '\0'; + char const *result = buf[index]; + index = (index + 1) % 8; + return result; } #ifdef __GNUC__ |