executable_darwin.go 613 B

1234567891011121314151617181920212223242526272829
  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. package os
  5. import "errors"
  6. var executablePath string // set by ../runtime/os_darwin.go
  7. var initCwd, initCwdErr = Getwd()
  8. func executable() (string, error) {
  9. ep := executablePath
  10. if len(ep) == 0 {
  11. return ep, errors.New("cannot find executable path")
  12. }
  13. if ep[0] != '/' {
  14. if initCwdErr != nil {
  15. return ep, initCwdErr
  16. }
  17. if len(ep) > 2 && ep[0:2] == "./" {
  18. // skip "./"
  19. ep = ep[2:]
  20. }
  21. ep = initCwd + "/" + ep
  22. }
  23. return ep, nil
  24. }