summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--userland/libc/include/tb/sb.h1
-rw-r--r--userland/libc/tb/sb.c14
2 files changed, 10 insertions, 5 deletions
diff --git a/userland/libc/include/tb/sb.h b/userland/libc/include/tb/sb.h
index 06aa084..c2fa1cf 100644
--- a/userland/libc/include/tb/sb.h
+++ b/userland/libc/include/tb/sb.h
@@ -22,4 +22,5 @@ void sb_append_buffer(struct sb *ctx, const char *buffer,
size_t length);
void sb_append_sv(struct sb *ctx, struct sv sv);
void sb_prepend_sv(struct sb *ctx, struct sv sv);
+void sb_prepend_buffer(struct sb *ctx, const char *buffer, size_t length);
#endif
diff --git a/userland/libc/tb/sb.c b/userland/libc/tb/sb.c
index f4e10f8..7ba83af 100644
--- a/userland/libc/tb/sb.c
+++ b/userland/libc/tb/sb.c
@@ -50,13 +50,17 @@ void sb_append(struct sb *ctx, const char *s) {
}
void sb_prepend_sv(struct sb *ctx, struct sv sv) {
- if (sv.length > ctx->capacity - ctx->length) {
- ctx->capacity += sv.length;
+ sb_prepend_buffer(ctx, sv.s, sv.length);
+}
+
+void sb_prepend_buffer(struct sb *ctx, const char *buffer, size_t length) {
+ if (length > ctx->capacity - ctx->length) {
+ ctx->capacity += length;
ctx->string = realloc(ctx->string, ctx->capacity);
}
- memmove(ctx->string + sv.length, ctx->string, ctx->length);
- memcpy(ctx->string, sv.s, sv.length);
- ctx->length += sv.length;
+ memmove(ctx->string + length, ctx->string, ctx->length);
+ memcpy(ctx->string, buffer, length);
+ ctx->length += length;
}
void sb_append_buffer(struct sb *ctx, const char *buffer, size_t length) {