summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--str.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/str.h b/str.h
index 33decac..96cf263 100644
--- a/str.h
+++ b/str.h
@@ -40,6 +40,7 @@ Str str_findc(Str s, char c);
Str str_find(Str haystack, Str needle);
int str_contains(Str a, Str b);
+char *cstr_dup(const char *s, Arena *a);
char *str_to_cstr(Str s, Arena *a);
void str_cat(Str *a, Str b, Arena *m);
void str_catc(Str *a, char b, Arena *m);
@@ -131,6 +132,13 @@ int str_contains(Str a, Str b) {
/* allocating */
+char *cstr_dup(const char *s, Arena *a) {
+ u32 n = strlen(s) + 1;
+ char *p = new_arr(a, char, n);
+ memcpy(p, s, n);
+ return p;
+}
+
char *str_to_cstr(Str s, Arena *a) {
if (!s.n) return "";
char *r = new_arr(a, char, s.n + 1);