aboutsummaryrefslogtreecommitdiffhomepage
path: root/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'common.c')
-rw-r--r--common.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/common.c b/common.c
index badb1ed..2c1fb37 100644
--- a/common.c
+++ b/common.c
@@ -12,7 +12,7 @@ void fatal_error(const char* msg, ...) {
#define unimplemented() fatal_error("%s:%d: unimplemented", __FILE__, __LINE__)
struct String {
- char* data;
+ const char* data;
size_t len;
};
typedef struct String String;
@@ -23,6 +23,13 @@ char* string_to_cstr(const String* s) {
return buf;
}
+String* cstr_to_new_string(const char* cstr) {
+ String* s = calloc(1, sizeof(String));
+ s->len = strlen(cstr);
+ s->data = strndup(cstr, s->len);
+ return s;
+}
+
BOOL string_equals(const String* s1, const String* s2) {
return s1->len == s2->len && strncmp(s1->data, s2->data, s1->len) == 0;
}