github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/os/executable_procfs.go (about) 1 // The following is copied from Go 1.17 official implementation. 2 3 // Copyright 2016 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 //go:build linux && !baremetal 8 9 package os 10 11 func Executable() (string, error) { 12 path, err := Readlink("/proc/self/exe") 13 14 // When the executable has been deleted then Readlink returns a 15 // path appended with " (deleted)". 16 return stringsTrimSuffix(path, " (deleted)"), err 17 } 18 19 // stringsTrimSuffix is the same as strings.TrimSuffix. 20 func stringsTrimSuffix(s, suffix string) string { 21 if len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix { 22 return s[:len(s)-len(suffix)] 23 } 24 return s 25 }