github.com/zxy12/go_duplicate_112_new@v0.0.0-20200807091221-747231827200/src/os/executable_darwin.go (about) 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 7 import "errors" 8 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 15 if len(ep) == 0 { 16 return ep, errors.New("cannot find executable path") 17 } 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 }