From e2bb7d70affdd14d4a9249749da24ff3670e5f3e Mon Sep 17 00:00:00 2001 From: imp0s5ible Date: Fri, 20 Mar 2026 15:21:12 +0100 Subject: [PATCH] Make map_file_from_path use the open flags map_file_from_path now passes the appropriate flags on to os.open instead of always calling it with os.O_RDWR. It will no longer try to open a file with write permissions if the user didn't request write access to the file mapping (or vice-versa). --- core/mem/virtual/file.odin | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/mem/virtual/file.odin b/core/mem/virtual/file.odin index 660210bbf..af0449e66 100644 --- a/core/mem/virtual/file.odin +++ b/core/mem/virtual/file.odin @@ -10,7 +10,14 @@ map_file :: proc{ } map_file_from_path :: proc(filename: string, flags: Map_File_Flags) -> (data: []byte, error: Map_File_Error) { - f, err := os.open(filename, os.O_RDWR) + open_flags : os.File_Flags + if .Read in flags { + open_flags += {.Read} + } + if .Write in flags { + open_flags += {.Write} + } + f, err := os.open(filename, open_flags) if err != nil { return nil, .Open_Failure } @@ -37,4 +44,4 @@ unmap_file :: proc(data: []byte) { if raw_data(data) != nil { _unmap_file(data) } -} \ No newline at end of file +}