summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--standard.c14
-rw-r--r--standard.h4
2 files changed, 18 insertions, 0 deletions
diff --git a/standard.c b/standard.c
index 96677ea..afe6ad4 100644
--- a/standard.c
+++ b/standard.c
@@ -1,4 +1,5 @@
#include "maths.h"
+#include "memory.h"
#include "standard.h"
int string_equal(const char* a, const char* b) {
@@ -17,6 +18,19 @@ int string_copy(char* dst, const char* src) {
return i;
}
+int string_len(const char* s) {
+ int l;
+ for (l = 0; *s; s++, l++);
+ return l;
+}
+
+char* dup_string(Arena* a, const char* s) {
+ int size = string_len(s) + 1;
+ char* d = arena_alloc_aligned(a, size, 1);
+ string_copy(d, s);
+ return d;
+}
+
int int_to_buf(int n, char* buf) {
int i, sign, t;
unsigned n1;
diff --git a/standard.h b/standard.h
index 8d58e78..2f82e40 100644
--- a/standard.h
+++ b/standard.h
@@ -3,8 +3,12 @@
#define no_mangle extern "C"
+struct Arena;
+
int string_equal(const char* a, const char* b);
int string_copy(char* dst, const char* src);
+int string_len(const char* s);
+char* dup_string(struct Arena* a, const char* s);
/* Not safe! */
int f_to_buf(int f, char* buf);