| 22 | { |
| 23 | |
| 24 | void* ReadFile(const char* path, uint32_t* file_size) |
| 25 | { |
| 26 | FILE* file = fopen(path, "rb"); |
| 27 | if (!file) |
| 28 | { |
| 29 | printf("Failed to load %s\n", path); |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | fseek(file, 0, SEEK_END); |
| 34 | size_t size = (size_t)ftell(file); |
| 35 | fseek(file, 0, SEEK_SET); |
| 36 | |
| 37 | void* mem = malloc(size); |
| 38 | |
| 39 | size_t nread = fread(mem, 1, size, file); |
| 40 | fclose(file); |
| 41 | |
| 42 | if (nread != size) |
| 43 | { |
| 44 | printf("Failed to read %u bytes from %s\n", (uint32_t)size, path); |
| 45 | free(mem); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | if (file_size) |
| 50 | *file_size = size; |
| 51 | |
| 52 | return mem; |
| 53 | } |
| 54 | |
| 55 | static void OutputIndent(int indent) |
| 56 | { |