From cdeeeafc3fbb1044abc872157d4354275f215c3d Mon Sep 17 00:00:00 2001 From: Platin21 Date: Thu, 22 Dec 2022 01:22:31 +0100 Subject: [PATCH 1/3] Fixed issues with dir opening on macOS --- core/os/os_darwin.odin | 1 + 1 file changed, 1 insertion(+) diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index 4c32323ff..3c69740c2 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -350,6 +350,7 @@ open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (Handle, Errno when ODIN_OS == .Darwin && ODIN_ARCH == .arm64 { if mode != 0 { + if mode != 0 && !is_dir_handle(handle) { err := fchmod(handle, cast(u16)mode) if err != 0 { _unix_close(handle) From fb562ea708b37ccfbbdba93afbbae5f1074f836b Mon Sep 17 00:00:00 2001 From: Platin21 Date: Thu, 22 Dec 2022 01:26:06 +0100 Subject: [PATCH 2/3] Adds error casting from last error if open fails --- core/os/os_darwin.odin | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index 3c69740c2..c5addb2bb 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -345,16 +345,15 @@ open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (Handle, Errno cstr := strings.clone_to_cstring(path, context.temp_allocator) handle := _unix_open(cstr, i32(flags), u16(mode)) if handle == -1 { - return INVALID_HANDLE, 1 + return INVALID_HANDLE, cast(Errno)get_last_error() } when ODIN_OS == .Darwin && ODIN_ARCH == .arm64 { - if mode != 0 { if mode != 0 && !is_dir_handle(handle) { err := fchmod(handle, cast(u16)mode) if err != 0 { _unix_close(handle) - return INVALID_HANDLE, 1 + return INVALID_HANDLE, cast(Errno)err } } } From b983ac548c0eb30c9be4b30a8d857a4ccebff4eb Mon Sep 17 00:00:00 2001 From: Platin21 Date: Thu, 22 Dec 2022 01:36:04 +0100 Subject: [PATCH 3/3] Moves check up and sets flag to rdonly if dir is opened.. --- core/os/os_darwin.odin | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index c5addb2bb..b40edb410 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -342,21 +342,33 @@ get_last_error_string :: proc() -> string { } open :: proc(path: string, flags: int = O_RDWR, mode: int = 0) -> (Handle, Errno) { + isDir := is_dir_path(path) + flags := flags + if isDir { + /* + @INFO(Platin): To make it impossible to use the wrong flag for dir's + as you can't write to a dir only read which makes it fail to open + */ + flags = O_RDONLY + } + cstr := strings.clone_to_cstring(path, context.temp_allocator) handle := _unix_open(cstr, i32(flags), u16(mode)) if handle == -1 { return INVALID_HANDLE, cast(Errno)get_last_error() } -when ODIN_OS == .Darwin && ODIN_ARCH == .arm64 { - if mode != 0 && !is_dir_handle(handle) { + /* + @INFO(Platin): this is only done because O_CREATE for some reason fails to apply mode + should not happen if the handle is a directory + */ + if mode != 0 && !isDir { err := fchmod(handle, cast(u16)mode) if err != 0 { _unix_close(handle) return INVALID_HANDLE, cast(Errno)err } } -} return handle, 0 }