summaryrefslogtreecommitdiff
path: root/src/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/string.c b/src/string.c
index be96c63..9328911 100644
--- a/src/string.c
+++ b/src/string.c
@@ -18,8 +18,31 @@ strng_t *strng_new(smrt_arena_t *arena, u64 size) {
strng_t *strng_from(smrt_arena_t *arena, char *c) {
u64 size = strlen(c);
- return strng_new(arena, size);
+ strng_t *s = strng_new(arena, size);
+
+ if (!s) {
+ return NULL;
+ }
+
+ memcpy((u8*)s+STRNG_BASE_POS, c, size);
+ s->len = size;
+
+ return s;
}
- b32 strng_set(strng_t *string, char *c);
- void strng_clear(strng_t *string);
+b32 strng_set(strng_t *string, char *c) {
+ u64 size = strlen(c);
+
+ if (string->alloc_size < size) {
+ return false;
+ }
+
+ memcpy((u8*)string+STRNG_BASE_POS, c, size);
+ string->len = size;
+
+ return true;
+}
+
+void strng_clear(strng_t *string) {
+ string->len = 0;
+}