summaryrefslogtreecommitdiff
path: root/libgo/go/os/exec/lp_plan9.go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-12-07 01:11:29 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2011-12-07 01:11:29 +0000
commit8388e3abaaaa0546c5f1c87a68e583958063cde9 (patch)
tree84f27a6ab44d932e4b0455f18390b070b4de626e /libgo/go/os/exec/lp_plan9.go
parentbc461ec935abe0c6f3e92be027143b4f25b5682f (diff)
downloadgcc-8388e3abaaaa0546c5f1c87a68e583958063cde9.tar.gz
libgo: Update to weekly 2011-11-09.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182073 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/os/exec/lp_plan9.go')
-rw-r--r--libgo/go/os/exec/lp_plan9.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/libgo/go/os/exec/lp_plan9.go b/libgo/go/os/exec/lp_plan9.go
new file mode 100644
index 00000000000..d4ffc17c006
--- /dev/null
+++ b/libgo/go/os/exec/lp_plan9.go
@@ -0,0 +1,52 @@
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package exec
+
+import (
+ "errors"
+ "os"
+ "strings"
+)
+
+// ErrNotFound is the error resulting if a path search failed to find an executable file.
+var ErrNotFound = errors.New("executable file not found in $path")
+
+func findExecutable(file string) error {
+ d, err := os.Stat(file)
+ if err != nil {
+ return err
+ }
+ if d.IsRegular() && d.Permission()&0111 != 0 {
+ return nil
+ }
+ return os.EPERM
+}
+
+// LookPath searches for an executable binary named file
+// in the directories named by the path environment variable.
+// If file begins with "/", "#", "./", or "../", it is tried
+// directly and the path is not consulted.
+func LookPath(file string) (string, error) {
+ // skip the path lookup for these prefixes
+ skip := []string{"/", "#", "./", "../"}
+
+ for _, p := range skip {
+ if strings.HasPrefix(file, p) {
+ err := findExecutable(file)
+ if err == nil {
+ return file, nil
+ }
+ return "", &Error{file, err}
+ }
+ }
+
+ path := os.Getenv("path")
+ for _, dir := range strings.Split(path, "\000") {
+ if err := findExecutable(dir + "/" + file); err == nil {
+ return dir + "/" + file, nil
+ }
+ }
+ return "", &Error{file, ErrNotFound}
+}