diff options
| author | 0x221E <0x221E@0xinfinity.dev> | 2026-04-12 16:24:06 +0200 |
|---|---|---|
| committer | 0x221E <0x221E@0xinfinity.dev> | 2026-04-12 16:24:06 +0200 |
| commit | 4946ca67cf04845737f0f7f70b5ed27bcfe9a18b (patch) | |
| tree | e0ce4c11f5b81828da7680143ea444003dd355b3 /src/sv.c | |
Diffstat (limited to 'src/sv.c')
| -rw-r--r-- | src/sv.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/sv.c b/src/sv.c new file mode 100644 index 0000000..d3debb3 --- /dev/null +++ b/src/sv.c @@ -0,0 +1,27 @@ +#include "sv.h" + +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +void sp_init(struct string_pool *sp) +{ + assert(sp != NULL); + sp->mem = (uintptr_t)malloc(1024*1024); + sp->offset = 0; +} + +struct string_view sv_create(struct string_pool *sp, const char *buf, size_t s) +{ + assert(sp != NULL); + if(buf == NULL) { + printf("Error: cannot create string! Buffer null!"); + exit(1); + } + + char* ptr = (char*)sp->mem + sp->offset; + memcpy((void*)ptr, buf, s); + sp->offset += s; + return (struct string_view) {.buf = ptr, .len = s}; +} |
