1
// Copyright 2015 The go4 Authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
15
// +build amd64,solaris
25
//go:cgo_import_dynamic libc_getexecname getexecname "libc.so"
26
//go:linkname libc_getexecname libc_getexecname
28
var libc_getexecname uintptr
30
func getexecname() (path unsafe.Pointer, err error) {
31
r0, _, e1 := syscall.Syscall6(uintptr(unsafe.Pointer(&libc_getexecname)), 0, 0, 0, 0, 0, 0)
32
path = unsafe.Pointer(r0)
34
err = syscall.Errno(e1)
39
func syscallGetexecname() (path string, err error) {
40
ptr, err := getexecname()
44
bytes := (*[1 << 29]byte)(ptr)[:]
45
for i, b := range bytes {
47
return string(bytes[:i]), nil
53
var initCwd, initCwdErr = os.Getwd()
55
func executable() (string, error) {
56
path, err := syscallGetexecname()
60
if len(path) > 0 && path[0] != '/' {
61
if initCwdErr != nil {
62
return path, initCwdErr
64
if len(path) > 2 && path[0:2] == "./" {
68
return initCwd + "/" + path, nil