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).
This commit is contained in:
imp0s5ible
2026-03-20 15:21:12 +01:00
parent 73df99fcb1
commit e2bb7d70af

View File

@@ -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)
}
}
}