Files
mop3/ce/strbuf.c
kamkow1 bdce9ef7c5
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 34s
Build documentation / build-and-deploy (push) Successful in 26s
CE Add copy command
2026-04-12 21:27:06 +02:00

30 lines
813 B
C

#include "strbuf.h"
#include "arena_alloc.h"
#include <arena.h>
#include <stddef.h>
void strbuf_append (struct strbuf* strbuf, char c) {
if (strbuf->items == NULL) {
strbuf->capacity = 256;
strbuf->count = 0;
strbuf->items = arena_malloc (&arena, strbuf->capacity);
} else {
if (strbuf->count == strbuf->capacity) {
size_t prev_capacity = strbuf->capacity;
strbuf->capacity *= 2;
strbuf->items = arena_realloc (&arena, strbuf->items, prev_capacity, strbuf->capacity);
}
}
strbuf->items[strbuf->count++] = c;
}
void strbuf_append_str (struct strbuf* strbuf, const char* s) {
while (*s)
strbuf_append (strbuf, *s++);
}
void strbuf_append_n (struct strbuf* strbuf, const char* s, size_t n) {
for (size_t i = 0; i < n; i++)
strbuf_append (strbuf, s[i]);
}