From 938f745f052c14fccaa987b98ea4ac84e70c1fcc Mon Sep 17 00:00:00 2001 From: Omniscient <17525998+omnisci3nce@users.noreply.github.com> Date: Sun, 25 Feb 2024 13:49:12 +1100 Subject: chore: format --- examples/standard_lib/ex_std.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/standard_lib/ex_std.c (limited to 'examples/standard_lib') diff --git a/examples/standard_lib/ex_std.c b/examples/standard_lib/ex_std.c new file mode 100644 index 0000000..9d474de --- /dev/null +++ b/examples/standard_lib/ex_std.c @@ -0,0 +1,30 @@ +#include +#include +#include "file.h" +#include "str.h" + +int main() { + // Examples of how to work with arenas and strings + size_t arena_size = 1024; + arena scratch = arena_create(malloc(arena_size), arena_size); + arena* a = &scratch; + + str8 hello = str8lit("Hello World"); + + // this works but we should be careful because str8 is not *guaranteed* to point to + // a null-terminated string + printf("String before: '%s' (null-terminated: %s) \n ", hello.buf, + str8_is_null_term(hello) ? "true" : "false"); + + char* c = str8_to_cstr(&scratch, hello); + + printf("String after: %s\n", c); + + str8_opt test_file = str8_from_file(&scratch, str8lit("assets/shaders/ui_rect.vert")); + if (test_file.has_value) { + printf("Contents: %.*s \n", (int)test_file.contents.len, test_file.contents.buf); + printf("Null-terminated: %s\n", str8_is_null_term(test_file.contents) ? "true" : "false"); + } + + return 0; +} -- cgit v1.2.3-70-g09d2