executable_solaris.go 763 B

123456789101112131415161718192021222324252627282930313233343536
  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 (
  6. "syscall"
  7. _ "unsafe" // for go:linkname
  8. )
  9. // solarisExecutablePath is defined in the runtime package.
  10. func solarisExecutablePath() string
  11. var initCwd, initCwdErr = Getwd()
  12. func executable() (string, error) {
  13. path := solarisExecutablePath()
  14. if len(path) == 0 {
  15. path, err := syscall.Getexecname()
  16. if err != nil {
  17. return path, err
  18. }
  19. }
  20. if len(path) > 0 && path[0] != '/' {
  21. if initCwdErr != nil {
  22. return path, initCwdErr
  23. }
  24. if len(path) > 2 && path[0:2] == "./" {
  25. // skip "./"
  26. path = path[2:]
  27. }
  28. return initCwd + "/" + path, nil
  29. }
  30. return path, nil
  31. }