blob: 9397fbb78234df50b7611674260d310ac5d3aace (
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
32
33
34
35
36
37
|
#ifndef BASE_OS_H
#define BASE_OS_H
internal string8
load_file(mem_arena *arena, const char *path)
{
string8 result = {0};
struct stat sbuf = {0};
s32 file = open(path, O_RDONLY);
if(file == -1)
{
warn("fialed to open file. path could be invalid");
return (string8){0};
}
if(fstat(file, &sbuf) == -1)
{
warn("error: fstat failed");
close(file);
return (string8){0};
}
result = PushString(arena, sbuf.st_size);
result.size = (u64)sbuf.st_size;
if(result.size != 0)
{
result.data = (u8 *)mmap(0, result.size, PROT_READ, MAP_PRIVATE, file, 0);
}
close(file);
return result;
}
#endif /* BASE_OS_H */
|