File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ import strings
66#include <errno.h>
77
88$if macos {
9- #include <libproc.h>
9+ #include <mach-o/dyld.h>
10+ // needed for os.executable():
11+ fn C._dyld_get_image_name (image u32 ) & char
1012}
1113
1214$if freebsd || openbsd {
@@ -765,14 +767,11 @@ pub fn executable() string {
765767 return res
766768 }
767769 $if macos {
768- pid := C.getpid ()
769- ret := C.proc_pidpath (pid, & result[0 ], max_path_len)
770- if ret < = 0 {
771- eprintln ('os.executable() failed at calling proc_pidpath with pid: ${pid } . proc_pidpath returned ${ret } ' )
770+ self_path := & char (C._dyld_get_image_name (u32 (0 )))
771+ if self_path == C.NULL {
772772 return executable_fallback ()
773773 }
774- res := unsafe { tos_clone (& result[0 ]) }
775- return res
774+ return unsafe { cstring_to_vstring (self_path) }
776775 }
777776 $if freebsd {
778777 bufsize := usize (max_path_buffer_size)
You can’t perform that action at this time.
0 commit comments