From 226d861c9ebb7f09f95665d07d9ab5c6b7ed7d6f Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Thu, 3 Oct 2024 15:08:45 +0200 Subject: libc: small changes --- userland/libc/tb/sv.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'userland/libc/tb/sv.c') diff --git a/userland/libc/tb/sv.c b/userland/libc/tb/sv.c index ac1c1e5..3f947ef 100644 --- a/userland/libc/tb/sv.c +++ b/userland/libc/tb/sv.c @@ -155,8 +155,25 @@ struct sv sv_take(struct sv s, struct sv *rest, size_t n) { return s; } s.length = n; - rest->length -= n; - rest->s += n; + if (rest) { + rest->length -= n; + rest->s += n; + } + return s; +} + +struct sv sv_take_end(struct sv s, struct sv *rest, size_t n) { + if (s.length < n) { + if (rest) { + rest->length = 0; + } + return s; + } + if (rest) { + rest->length = s.length - n; + } + s.s += (s.length - n); + s.length = n; return s; } -- cgit v1.2.3