From 75705ca3d91930a730743b5319268087fc7bc56e Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 19 Jul 2025 09:29:54 -0700 Subject: New filesystem API --- filesystem/include/filesystem.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'filesystem/include/filesystem.h') 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 @@ #include #include +#define WITH_FILE(FILEPATH, BODY) \ + { \ + assert(FILEPATH); \ + FILE* file = fopen(FILEPATH, "rb"); \ + if (file) { \ + BODY; \ + fclose(file); \ + } \ + } + +/// Get the file's size. +size_t get_file_size(const char* filename); + /// Get the file's size. -size_t get_file_size(FILE* file); +size_t get_file_size_f(FILE* file); /// Read the entire contents of the file into memory. void* read_file(const char* filepath); + +/// Read the entire contents of the file into memory. +/// +/// The given buffer must be large enough to hold the file's contents. +bool read_file_f(FILE*, void* buffer); -- cgit v1.2.3