From 3f6096c322192c7024d5eae8b21a3e5f24f6903e Mon Sep 17 00:00:00 2001 From: nasr Date: Tue, 17 Mar 2026 18:08:47 +0000 Subject: feature(base): file writing using string struct not the ideal way i think. i thought handmade hero had a different way but will take a look at that later --- source/base/base_os.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/source/base/base_os.h b/source/base/base_os.h index 9397fbb..388f665 100644 --- a/source/base/base_os.h +++ b/source/base/base_os.h @@ -34,4 +34,34 @@ load_file(mem_arena *arena, const char *path) return result; } +internal string8 +write_file(const char *path, string8 data) +{ + + string8 result = {0}; + s32 file = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); + if(file == -1) + { + warn("failed to open file for writing. path could be invalid"); + return (string8){0}; + } + + u64 written = 0; + while(written < data.size) + { + s64 err = write(file, data.data + written, data.size - written); + if(err == -1) + { + warn("write syscall failed"); + close(file); + return (string8){0}; + } + written += err; + } + + close(file); + result = data; + return result; +} + #endif /* BASE_OS_H */ -- cgit v1.3