summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/kit/string_ref.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/source/kit/string_ref.h b/source/kit/string_ref.h
index 1497bb0..6c89292 100644
--- a/source/kit/string_ref.h
+++ b/source/kit/string_ref.h
@@ -2,6 +2,7 @@
#define KIT_STRING_REF_H
#include "array_ref.h"
+#include <string.h>
#ifdef __cplusplus
extern "C" {
@@ -27,6 +28,19 @@ static kit_str_t kit_str(ptrdiff_t const size,
return s;
}
+/* Make a barbarian string for C standard library functions.
+ * Not thread safe.
+ */
+static char const *kit_make_bs(kit_str_t const s) {
+ static char buf[4096];
+ ptrdiff_t n = s.size;
+ if (n > 4095)
+ n = 4095;
+ memcpy(buf, s.values, n);
+ buf[n] = '\0';
+ return buf;
+}
+
#ifdef __GNUC__
# pragma GCC pop_options
# pragma GCC diagnostic pop
@@ -35,6 +49,8 @@ static kit_str_t kit_str(ptrdiff_t const size,
#define KIT_SZ(static_str_) \
kit_str(sizeof(static_str_) - 1, (static_str_))
+#define KIT_WRAP_BS(string_) kit_str(strlen(string_), (string_))
+
#define KIT_WRAP_STR(string_) \
kit_str((string_).size, (string_).values)
@@ -45,6 +61,8 @@ static kit_str_t kit_str(ptrdiff_t const size,
# define str_t kit_str_t
# define SZ KIT_SZ
+# define BS kit_make_bs
+# define WRAP_BS KIT_WRAP_BS
# define WRAP_STR KIT_WRAP_STR
#endif