From a137699d9535092f7c88972e668afab125dfa558 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 13 Nov 2017 20:35:21 +0000 Subject: [PATCH] Add optional truncate parameter to write_entire_file (#144) --- core/os.odin | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/os.odin b/core/os.odin index f982dd270..8f7a4ff92 100644 --- a/core/os.odin +++ b/core/os.odin @@ -37,8 +37,12 @@ read_entire_file :: proc(name: string) -> (data: []u8, success: bool) { return data[0..bytes_read], true; } -write_entire_file :: proc(name: string, data: []u8) -> (success: bool) { - fd, err := open(name, O_WRONLY|O_CREATE, 0); +write_entire_file :: proc(name: string, data: []u8, truncate := true) -> (success: bool) { + flags: int = O_WRONLY|O_CREATE; + if truncate { + flags |= O_TRUNC; + } + fd, err := open(name, flags, 0); if err != 0 { return false; }