summaryrefslogtreecommitdiff
path: root/src/sv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sv.c')
-rw-r--r--src/sv.c27
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};
+}