diff options
| author | nasr <nsrddyn@gmail.com> | 2026-03-26 22:35:30 +0100 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-13 17:24:42 +0200 |
| commit | dd5586abec207dd4acd16d51ce0d392c03e5e957 (patch) | |
| tree | e56573f49ebb2a3236a39148842dc80bde5a286d /source/base/base_os.h | |
feature(main): initmain
feature(main): init
Diffstat (limited to 'source/base/base_os.h')
| -rw-r--r-- | source/base/base_os.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/source/base/base_os.h b/source/base/base_os.h new file mode 100644 index 0000000..23587c6 --- /dev/null +++ b/source/base/base_os.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #ifndef BASE_OS_H | ||
| 2 | #define BASE_OS_H | ||
| 3 | |||
| 4 | internal void | ||
| 5 | print(const char *str) | ||
| 6 | { | ||
| 7 | i32 len = 0; | ||
| 8 | while (str[len]) len++; | ||
| 9 | write(STDOUT_FILENO, str, len); | ||
| 10 | } | ||
| 11 | |||
| 12 | internal string8 | ||
| 13 | load_file(const char *path) | ||
| 14 | { | ||
| 15 | string8 result = {0}; | ||
| 16 | struct stat sbuf = {0}; | ||
| 17 | |||
| 18 | i32 file = open(path, O_RDONLY); | ||
| 19 | if(file == -1) return result; | ||
| 20 | |||
| 21 | if(fstat(file, &sbuf) == -1) | ||
| 22 | { | ||
| 23 | print("error: fstat failed"); | ||
| 24 | close(file); | ||
| 25 | return result; | ||
| 26 | } | ||
| 27 | |||
| 28 | result.size = (u64)sbuf.st_size; | ||
| 29 | if(result.size != 0) | ||
| 30 | { | ||
| 31 | result.data = (u8 *)mmap(0, result.size, PROT_READ, MAP_PRIVATE, file, 0); | ||
| 32 | } | ||
| 33 | |||
| 34 | close(file); | ||
| 35 | return result; | ||
| 36 | } | ||
| 37 | |||
| 38 | #endif /* BASE_OS_H */ | ||
