mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
os/os2: use proc_pidpath for executable path on darwin
This commit is contained in:
@@ -6,26 +6,12 @@ import "core:sys/darwin"
|
|||||||
import "core:sys/posix"
|
import "core:sys/posix"
|
||||||
|
|
||||||
_get_executable_path :: proc(allocator: runtime.Allocator) -> (path: string, err: Error) {
|
_get_executable_path :: proc(allocator: runtime.Allocator) -> (path: string, err: Error) {
|
||||||
size: u32
|
buffer: [darwin.PIDPATHINFO_MAXSIZE]byte = ---
|
||||||
|
ret := darwin.proc_pidpath(posix.getpid(), raw_data(buffer[:]), len(buffer))
|
||||||
ret := darwin._NSGetExecutablePath(nil, &size)
|
if ret > 0 {
|
||||||
assert(ret == -1)
|
return clone_string(string(buffer[:ret]), allocator)
|
||||||
assert(size > 0)
|
|
||||||
|
|
||||||
TEMP_ALLOCATOR_GUARD()
|
|
||||||
|
|
||||||
buf := make([]byte, size, temp_allocator()) or_return
|
|
||||||
assert(u32(len(buf)) == size)
|
|
||||||
|
|
||||||
ret = darwin._NSGetExecutablePath(raw_data(buf), &size)
|
|
||||||
assert(ret == 0)
|
|
||||||
|
|
||||||
real := posix.realpath(cstring(raw_data(buf)))
|
|
||||||
if real == nil {
|
|
||||||
err = _get_platform_error()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
defer posix.free(real)
|
|
||||||
|
|
||||||
return clone_string(string(real), allocator)
|
err = _get_platform_error()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package darwin
|
|
||||||
|
|
||||||
foreign import system "system:System.framework"
|
|
||||||
|
|
||||||
foreign system {
|
|
||||||
_NSGetExecutablePath :: proc(buf: [^]byte, bufsize: ^u32) -> i32 ---
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user