diff options
Diffstat (limited to 'common.c')
| -rw-r--r-- | common.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; } |
