Source file
src/os/exec/lp_plan9.go
1
2
3
4
5 package exec
6
7 import (
8 "errors"
9 "io/fs"
10 "os"
11 "path/filepath"
12 "strings"
13 )
14
15
16 var ErrNotFound = errors.New("executable file not found in $path")
17
18 func findExecutable(file string) error {
19 d, err := os.Stat(file)
20 if err != nil {
21 return err
22 }
23 if m := d.Mode(); !m.IsDir() && m&0111 != 0 {
24 return nil
25 }
26 return fs.ErrPermission
27 }
28
29
30
31
32
33
34
35
36
37
38 func LookPath(file string) (string, error) {
39 if err := validateLookPath(file); err != nil {
40 return "", &Error{file, err}
41 }
42
43
44 skip := []string{"/", "#", "./", "../"}
45
46 for _, p := range skip {
47 if strings.HasPrefix(file, p) {
48 err := findExecutable(file)
49 if err == nil {
50 return file, nil
51 }
52 return "", &Error{file, err}
53 }
54 }
55
56 path := os.Getenv("path")
57 for _, dir := range filepath.SplitList(path) {
58 path := filepath.Join(dir, file)
59 if err := findExecutable(path); err == nil {
60 if !filepath.IsAbs(path) {
61 if execerrdot.Value() != "0" {
62 return path, &Error{file, ErrDot}
63 }
64 execerrdot.IncNonDefault()
65 }
66 return path, nil
67 }
68 }
69 return "", &Error{file, ErrNotFound}
70 }
71
72
73
74 func lookExtensions(path, dir string) (string, error) {
75 return path, nil
76 }
77
View as plain text