Files
mop3/ce/strbuf.c
kamkow1 c8fb575bdd
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 2m7s
Build documentation / build-and-deploy (push) Successful in 39s
Change formatting rules
2026-04-24 01:54:48 +02:00

30 lines
806 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]);
}