diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-08-24 22:53:21 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-08-27 11:46:25 +0200 |
| commit | 8e478e06c2c09e8d74fcaa6cca84f7db14d23265 (patch) | |
| tree | c1913a33402c9b63f6cbc1288d05d1ef4c48bb7c /src/testing.c | |
| parent | dd2c70e878e4bc7fcf26f33523a45f0d854a29e4 (diff) | |
improved testing & src cleanup
Diffstat (limited to 'src/testing.c')
| -rw-r--r-- | src/testing.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/testing.c b/src/testing.c new file mode 100644 index 0000000..937d2dc --- /dev/null +++ b/src/testing.c @@ -0,0 +1,28 @@ +#include <stdio.h> + +#include "../include/assert.h" +#include "../include/memory.h" +#include "../include/str.h" +#include "../include/testing.h" +#include "../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; +} |
