From cf949e541f9a5abd1785c2a382f1de5b706dfd8b Mon Sep 17 00:00:00 2001 From: Beau McCartney Date: Fri, 15 Mar 2024 08:11:10 -0600 Subject: [PATCH] helper function to convert Open_Flags bitset to a u32 - analagous to _sys_permission_mode() - uses the already-existing conversion logic in sys_open() --- core/sys/darwin/xnu_system_call_helpers.odin | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/sys/darwin/xnu_system_call_helpers.odin b/core/sys/darwin/xnu_system_call_helpers.odin index 753f7f058..06cf26178 100644 --- a/core/sys/darwin/xnu_system_call_helpers.odin +++ b/core/sys/darwin/xnu_system_call_helpers.odin @@ -87,6 +87,29 @@ _sys_permission_mode :: #force_inline proc (mode: Permission) -> u32 { return cflags } +_sys_open_mode :: #force_inline proc(mode: Open_Flags) -> u32 { + cflags : u32 = 0 + + cflags |= OPEN_FLAG_RDONLY * u32(Open_Flags.RDONLY in mode) + cflags |= OPEN_FLAG_WRONLY * u32(Open_Flags.WRONLY in mode) + cflags |= OPEN_FLAG_RDWR * u32(Open_Flags.RDWR in mode) + cflags |= OPEN_FLAG_NONBLOCK * u32(Open_Flags.NONBLOCK in mode) + cflags |= OPEN_FLAG_CREAT * u32(Open_Flags.CREAT in mode) + cflags |= OPEN_FLAG_APPEND * u32(Open_Flags.APPEND in mode) + cflags |= OPEN_FLAG_TRUNC * u32(Open_Flags.TRUNC in mode) + cflags |= OPEN_FLAG_EXCL * u32(Open_Flags.EXCL in mode) + cflags |= OPEN_FLAG_SHLOCK * u32(Open_Flags.SHLOCK in mode) + cflags |= OPEN_FLAG_EXLOCK * u32(Open_Flags.EXLOCK in mode) + cflags |= OPEN_FLAG_DIRECTORY * u32(Open_Flags.DIRECTORY in mode) + cflags |= OPEN_FLAG_NOFOLLOW * u32(Open_Flags.NOFOLLOW in mode) + cflags |= OPEN_FLAG_SYMLINK * u32(Open_Flags.SYMLINK in mode) + cflags |= OPEN_FLAG_EVTONLY * u32(Open_Flags.EVTONLY in mode) + cflags |= OPEN_FLAG_CLOEXEC * u32(Open_Flags.CLOEXEC in mode) + cflags |= OPEN_FLAG_NOFOLLOW_ANY * u32(Open_Flags.NOFOLLOW_ANY in mode) + + return cflags +} + @(private) clone_to_cstring :: proc(s: string, allocator: runtime.Allocator, loc := #caller_location) -> cstring { c := make([]byte, len(s)+1, allocator, loc)