From dd5586abec207dd4acd16d51ce0d392c03e5e957 Mon Sep 17 00:00:00 2001 From: nasr Date: Thu, 26 Mar 2026 22:35:30 +0100 Subject: feature(main): init feature(main): init --- source/base/base_os.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 source/base/base_os.h (limited to 'source/base/base_os.h') 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 @@ +#ifndef BASE_OS_H +#define BASE_OS_H + +internal void +print(const char *str) +{ + i32 len = 0; + while (str[len]) len++; + write(STDOUT_FILENO, str, len); +} + +internal string8 +load_file(const char *path) +{ + string8 result = {0}; + struct stat sbuf = {0}; + + i32 file = open(path, O_RDONLY); + if(file == -1) return result; + + if(fstat(file, &sbuf) == -1) + { + print("error: fstat failed"); + close(file); + return result; + } + + 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 */ -- cgit v1.3