From: Shenghou Ma Date: Sun, 1 Nov 2015 09:16:52 +0000 (-0500) Subject: runtime: os.Executable runtime support for Darwin X-Git-Tag: go1.8beta1~275 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2058511e4e5966a7d482beb6033c68e324aa09ac;p=gostls13.git runtime: os.Executable runtime support for Darwin Change-Id: Ie21df37016c90cd0479c23ec4845f8195dd90fda Reviewed-on: https://go-review.googlesource.com/16518 Reviewed-by: Brad Fitzpatrick Reviewed-by: Russ Cox Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/runtime/os_darwin.go b/src/runtime/os_darwin.go index 0dfe8778db..15281674ae 100644 --- a/src/runtime/os_darwin.go +++ b/src/runtime/os_darwin.go @@ -551,3 +551,21 @@ func sigaddset(mask *sigset, i int) { func sigdelset(mask *sigset, i int) { *mask &^= 1 << (uint32(i) - 1) } + +//go:linkname executablePath os.executablePath +var executablePath string + +func sysargs(argc int32, argv **byte) { + // skip over argv, envv and the first string will be the path + n := argc + 1 + for argv_index(argv, n) != nil { + n++ + } + executablePath = gostringnocopy(argv_index(argv, n+1)) + + // strip "executable_path=" prefix if available, it's added after OS X 10.11. + const prefix = "executable_path=" + if len(executablePath) > len(prefix) && executablePath[:len(prefix)] == prefix { + executablePath = executablePath[len(prefix):] + } +} diff --git a/src/runtime/vdso_none.go b/src/runtime/vdso_none.go index efae23f6ee..fc2124040f 100644 --- a/src/runtime/vdso_none.go +++ b/src/runtime/vdso_none.go @@ -3,6 +3,7 @@ // license that can be found in the LICENSE file. // +build !linux +// +build !darwin package runtime