blob: bc7f953c8d37b45fae5e277f6bb1534f91034f8e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
/*
* Various filesystem utilities.
*/
#pragma once
#include <stddef.h>
#include <stdio.h>
#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_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);
|