From 4e77bc7164070d7ffafdee1ba6ce3bb1aaf10746 Mon Sep 17 00:00:00 2001 From: nasr Date: Mon, 2 Mar 2026 22:44:17 +0000 Subject: feature(main): loading file + bug fixes structure improvement --- source/base/base_os.h | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'source/base/base_os.h') 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) write(STDOUT_FILENO, str, len); } -#define print(Format) print(Format) +internal string8 +load_file(const char *path) +{ + string8 result = {0}; + struct stat sbuf = {0}; + int err = 0; + i32 file = open(path, O_RDONLY); + + if(file) + { + + if(file != -1) + { + err = fstat(file, &sbuf); + check(err != -1); + + result.size = (u64)sbuf.st_size; + + if(result.size != 0) + { + result.data = (u8 *)mmap(0, + result.size, + PROT_READ, + MAP_PRIVATE, + file, + 0); + + check(result.data != MAP_FAILED); + } + + close(file); + } + else + { + // TODO(nasr): logging + } + + } + return result; +} #endif /* BASE_OS_H */ -- cgit v1.3