Shenghou Ma | 2fc67e7 | 2015-11-01 04:18:58 -0500 | [diff] [blame] | 1 | // Copyright 2016 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package os |
| 6 | |
Roberto Clapis | faadda0 | 2018-08-02 15:27:14 +0200 | [diff] [blame] | 7 | import "errors" |
| 8 | |
Shenghou Ma | 2fc67e7 | 2015-11-01 04:18:58 -0500 | [diff] [blame] | 9 | var executablePath string // set by ../runtime/os_darwin.go |
| 10 | |
| 11 | var initCwd, initCwdErr = Getwd() |
| 12 | |
| 13 | func executable() (string, error) { |
| 14 | ep := executablePath |
Roberto Clapis | faadda0 | 2018-08-02 15:27:14 +0200 | [diff] [blame] | 15 | if len(ep) == 0 { |
| 16 | return ep, errors.New("cannot find executable path") |
| 17 | } |
Shenghou Ma | 2fc67e7 | 2015-11-01 04:18:58 -0500 | [diff] [blame] | 18 | if ep[0] != '/' { |
| 19 | if initCwdErr != nil { |
| 20 | return ep, initCwdErr |
| 21 | } |
| 22 | if len(ep) > 2 && ep[0:2] == "./" { |
| 23 | // skip "./" |
| 24 | ep = ep[2:] |
| 25 | } |
| 26 | ep = initCwd + "/" + ep |
| 27 | } |
| 28 | return ep, nil |
| 29 | } |