diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-04-08 13:14:27 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-04-08 13:15:01 +0200 |
| commit | cf534d762754860ed5b714974f99acd282d48b3b (patch) | |
| tree | bf22341cedfb50ee7bcd4e15f85add2329783f31 /src/std/testing.c | |
| parent | 630fcb1846aed16b9ab62bcf700f668883f4521f (diff) | |
Restructure into src/{std,json}/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/std/testing.c')
| -rw-r--r-- | src/std/testing.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/std/testing.c b/src/std/testing.c new file mode 100644 index 0000000..af2d1c8 --- /dev/null +++ b/src/std/testing.c @@ -0,0 +1,28 @@ +#include <stdio.h> + +#include "assert.h" +#include "memory.h" +#include "str.h" +#include "testing.h" +#include "types.h" + +MemoryFile load_file(Arena *a, const char *filename) { + FILE *file = fopen(filename, "rb"); + assert(file != 0, "failed to open file: %s", filename); + MemoryFile mem_file = {0}; + + // Get file size + fseek(file, 0, SEEK_END); + mem_file.size = ftell(file); + fseek(file, 0, SEEK_SET); + + mem_file.content = new(a, byte, mem_file.size + 1); + + size bytes_read = fread(mem_file.content, 1, mem_file.size, file); + assert(bytes_read == mem_file.size, "failed to read entire file: %s", + filename); + + mem_file.content[mem_file.size] = '\0'; // Null terminate + fclose(file); + return mem_file; +} |
