blob: 4c8486fbcca8e355e2ed6e494da686fcb9cd553c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
u64 CstrSize(const char* cstr)
{
u8 *iter = (u8*)cstr;
u64 size = 0;
for(;*iter != 0; *iter++) {
size += 1;
}
return size;
}
struct str8 Str8(u8 *string, u64 size)
{
struct str8 result = {string, size};
return result;
}
struct res_str8 Str8InitCstr(struct arena *a, const char* cstr)
{
u64 cstr_size = CstrSize(cstr);
struct res_void cstr_res = arena_alloc(a, cstr_size);
u8 *str = (u8 *)cstr_res.memory;
u64 str_size = cstr_res.bytes_count;
MemCopy((void*)str, (void*)cstr, str_size*sizeof(u8));
struct res_str8 result = {};
result.string = Str8(str, str_size);
result.bytes_count = str_size;
return result;
}
|