diff options
author | Anton Kling <anton@kling.gg> | 2024-10-03 15:08:45 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-10-03 15:08:45 +0200 |
commit | 226d861c9ebb7f09f95665d07d9ab5c6b7ed7d6f (patch) | |
tree | d900c3437d3d65ee7bd88474586dc6dd947b14ce /userland/libc/tb/sv.c | |
parent | 64b0b49a1f23da9faa680f8158cb8a12cd4d118c (diff) |
libc: small changes
Diffstat (limited to 'userland/libc/tb/sv.c')
-rw-r--r-- | userland/libc/tb/sv.c | 21 |
1 files changed, 19 insertions, 2 deletions
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; } |