summaryrefslogtreecommitdiff
path: root/userland/libc/tb/sv.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-10-14 16:37:18 +0200
committerAnton Kling <anton@kling.gg>2024-10-14 16:37:18 +0200
commit3fd4be7cb2744d852cf99e627f7bfea3fd83bd3c (patch)
tree0d2e2a9d5b85aaf631e551ba88be0930e715c711 /userland/libc/tb/sv.c
parent3011c0589b8ab7cbfed127ce45a04f154441b406 (diff)
libc: Copy string views to preallocated buffers
Diffstat (limited to 'userland/libc/tb/sv.c')
-rw-r--r--userland/libc/tb/sv.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/userland/libc/tb/sv.c b/userland/libc/tb/sv.c
index 3f947ef..4ff24fb 100644
--- a/userland/libc/tb/sv.c
+++ b/userland/libc/tb/sv.c
@@ -11,6 +11,15 @@ char *SV_TO_C(struct sv s) {
return c_string;
}
+size_t sv_to_cstring_buffer(struct sv s, char *buffer, size_t length) {
+ if (0 == length || length - 1 < s.length) {
+ return s.length;
+ }
+ memcpy(buffer, s.s, s.length);
+ buffer[s.length] = '\0';
+ return s.length;
+}
+
struct sv sv_next(struct sv s) {
if (0 == s.length) {
return s;