aboutsummaryrefslogtreecommitdiff
path: root/filesystem/include
diff options
context:
space:
mode:
Diffstat (limited to 'filesystem/include')
-rw-r--r--filesystem/include/filesystem.h20
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.
20size_t get_file_size(const char* filename);
21
9/// Get the file's size. 22/// Get the file's size.
10size_t get_file_size(FILE* file); 23size_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.
13void* read_file(const char* filepath); 26void* 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.
31bool read_file_f(FILE*, void* buffer);