Skip to content

Commit e475110

Browse files
os: use _dyld_get_image_name() to increase compatibility with older versions of Mac OS X like 10.4 (#26617)
1 parent 2dd15d9 commit e475110

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

‎vlib/os/os.c.v‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)