diff options
| author | 3gg <3gg@shellblade.net> | 2025-07-19 09:29:54 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-07-19 09:29:54 -0700 |
| commit | 75705ca3d91930a730743b5319268087fc7bc56e (patch) | |
| tree | 266fe906020a01559e1f5ca19f41b1e4c7252100 /filesystem/include | |
| parent | ff565e8d422c5e58558d1f7682ba0c9756e5be27 (diff) | |
New filesystem API
Diffstat (limited to 'filesystem/include')
| -rw-r--r-- | filesystem/include/filesystem.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/filesystem/include/filesystem.h b/filesystem/include/filesystem.h index 1c354b7..bc7f953 100644 --- a/filesystem/include/filesystem.h +++ b/filesystem/include/filesystem.h | |||
| @@ -6,8 +6,26 @@ | |||
| 6 | #include <stddef.h> | 6 | #include <stddef.h> |
| 7 | #include <stdio.h> | 7 | #include <stdio.h> |
| 8 | 8 | ||
| 9 | #define WITH_FILE(FILEPATH, BODY) \ | ||
| 10 | { \ | ||
| 11 | assert(FILEPATH); \ | ||
| 12 | FILE* file = fopen(FILEPATH, "rb"); \ | ||
| 13 | if (file) { \ | ||
| 14 | BODY; \ | ||
| 15 | fclose(file); \ | ||
| 16 | } \ | ||
| 17 | } | ||
| 18 | |||
| 19 | /// Get the file's size. | ||
| 20 | size_t get_file_size(const char* filename); | ||
| 21 | |||
| 9 | /// Get the file's size. | 22 | /// Get the file's size. |
| 10 | size_t get_file_size(FILE* file); | 23 | size_t get_file_size_f(FILE* file); |
| 11 | 24 | ||
| 12 | /// Read the entire contents of the file into memory. | 25 | /// Read the entire contents of the file into memory. |
| 13 | void* read_file(const char* filepath); | 26 | void* read_file(const char* filepath); |
| 27 | |||
| 28 | /// Read the entire contents of the file into memory. | ||
| 29 | /// | ||
| 30 | /// The given buffer must be large enough to hold the file's contents. | ||
| 31 | bool read_file_f(FILE*, void* buffer); | ||
