mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-03 04:38:54 +00:00
fix file open emulating posix open on mode/perm mismatch on windows
This commit is contained in:
@@ -542,7 +542,7 @@ _open_sync :: proc(l: ^Event_Loop, name: string, dir: Handle, mode: File_Flags,
|
||||
association_err: Association_Error
|
||||
handle, association_err = _associate_handle(uintptr(h), l)
|
||||
// This shouldn't fail, we just created this file, with correct flags.
|
||||
assert(association_err != nil)
|
||||
assert(association_err == nil)
|
||||
return
|
||||
case:
|
||||
err = FS_Error(syserr)
|
||||
|
||||
@@ -130,16 +130,17 @@ _open_internal :: proc(name: string, flags: File_Flags, perm: Permissions) -> (h
|
||||
if .Non_Blocking in flags {
|
||||
nix_attrs |= win32.FILE_FLAG_OVERLAPPED
|
||||
}
|
||||
h := win32.CreateFileW(path, access, share_mode, &sa, win32.TRUNCATE_EXISTING, nix_attrs, nil)
|
||||
if h == win32.INVALID_HANDLE {
|
||||
switch e := win32.GetLastError(); e {
|
||||
case win32.ERROR_FILE_NOT_FOUND, _ERROR_BAD_NETPATH, win32.ERROR_PATH_NOT_FOUND:
|
||||
// file does not exist, create the file
|
||||
case 0:
|
||||
return uintptr(h), nil
|
||||
case:
|
||||
return 0, _get_platform_error()
|
||||
}
|
||||
|
||||
h := win32.CreateFileW(path, access | win32.GENERIC_WRITE, share_mode, &sa, win32.TRUNCATE_EXISTING, nix_attrs, nil)
|
||||
if h != win32.INVALID_HANDLE {
|
||||
// File exists and is now truncated, preserving attributes.
|
||||
return uintptr(h), nil
|
||||
}
|
||||
switch e := win32.GetLastError(); e {
|
||||
case win32.ERROR_FILE_NOT_FOUND, _ERROR_BAD_NETPATH, win32.ERROR_PATH_NOT_FOUND:
|
||||
// File does not exist, fall through and create it.
|
||||
case:
|
||||
return 0, _get_platform_error()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user