aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/exec/lp_unix.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2011-09-16 15:47:21 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-09-16 15:47:21 +0000
commitadb0401dac41c81571722312d4586b2693f95aa6 (patch)
treeea2b52e3c258d6b6d9356977c683c7f72a4a5fd5 /libgo/go/exec/lp_unix.go
parent5548ca3540bccbc908a45942896d635ea5f1c23f (diff)
downloadgcc-adb0401dac41c81571722312d4586b2693f95aa6.zip
gcc-adb0401dac41c81571722312d4586b2693f95aa6.tar.gz
gcc-adb0401dac41c81571722312d4586b2693f95aa6.tar.bz2
Update Go library to r60.
From-SVN: r178910
Diffstat (limited to 'libgo/go/exec/lp_unix.go')
-rw-r--r--libgo/go/exec/lp_unix.go23
1 files changed, 15 insertions, 8 deletions
diff --git a/libgo/go/exec/lp_unix.go b/libgo/go/exec/lp_unix.go
index 44f8434..008fb11 100644
--- a/libgo/go/exec/lp_unix.go
+++ b/libgo/go/exec/lp_unix.go
@@ -9,12 +9,18 @@ import (
"strings"
)
-func canExec(file string) bool {
+// ErrNotFound is the error resulting if a path search failed to find an executable file.
+var ErrNotFound = os.NewError("executable file not found in $PATH")
+
+func findExecutable(file string) os.Error {
d, err := os.Stat(file)
if err != nil {
- return false
+ return err
+ }
+ if d.IsRegular() && d.Permission()&0111 != 0 {
+ return nil
}
- return d.IsRegular() && d.Permission()&0111 != 0
+ return os.EPERM
}
// LookPath searches for an executable binary named file
@@ -26,20 +32,21 @@ func LookPath(file string) (string, os.Error) {
// but that would not match all the Unix shells.
if strings.Contains(file, "/") {
- if canExec(file) {
+ err := findExecutable(file)
+ if err == nil {
return file, nil
}
- return "", &PathError{file}
+ return "", &Error{file, err}
}
pathenv := os.Getenv("PATH")
- for _, dir := range strings.Split(pathenv, ":", -1) {
+ for _, dir := range strings.Split(pathenv, ":") {
if dir == "" {
// Unix shell semantics: path element "" means "."
dir = "."
}
- if canExec(dir + "/" + file) {
+ if err := findExecutable(dir + "/" + file); err == nil {
return dir + "/" + file, nil
}
}
- return "", &PathError{file}
+ return "", &Error{file, ErrNotFound}
}