blob: d3debb3aba4dce58b6086ec64b35098ea1ec9487 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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};
}
|