summaryrefslogtreecommitdiff
path: root/source/base/base_os.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/base/base_os.h')
-rw-r--r--source/base/base_os.h41
1 files changed, 40 insertions, 1 deletions
diff --git a/source/base/base_os.h b/source/base/base_os.h
index ce9acae..ec0a3de 100644
--- a/source/base/base_os.h
+++ b/source/base/base_os.h
@@ -9,6 +9,45 @@ print(const char *str)
9 write(STDOUT_FILENO, str, len); 9 write(STDOUT_FILENO, str, len);
10} 10}
11 11
12#define print(Format) print(Format) 12internal string8
13load_file(const char *path)
14{
15 string8 result = {0};
16 struct stat sbuf = {0};
17 int err = 0;
18 i32 file = open(path, O_RDONLY);
19
20 if(file)
21 {
22
23 if(file != -1)
24 {
25 err = fstat(file, &sbuf);
26 check(err != -1);
27
28 result.size = (u64)sbuf.st_size;
29
30 if(result.size != 0)
31 {
32 result.data = (u8 *)mmap(0,
33 result.size,
34 PROT_READ,
35 MAP_PRIVATE,
36 file,
37 0);
38
39 check(result.data != MAP_FAILED);
40 }
41
42 close(file);
43 }
44 else
45 {
46 // TODO(nasr): logging
47 }
48
49 }
50 return result;
51}
13 52
14#endif /* BASE_OS_H */ 53#endif /* BASE_OS_H */