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
40 skip := []string{"/", "#", "./", "../"}
41
42 for _, p := range skip {
43 if strings.HasPrefix(file, p) {
44 err := findExecutable(file)
45 if err == nil {
46 return file, nil
47 }
48 return "", &Error{file, err}
49 }
50 }
51
52 path := os.Getenv("path")
53 for _, dir := range filepath.SplitList(path) {
54 path := filepath.Join(dir, file)
55 if err := findExecutable(path); err == nil {
56 if !filepath.IsAbs(path) {
57 if execerrdot.Value() != "0" {
58 return path, &Error{file, ErrDot}
59 }
60 execerrdot.IncNonDefault()
61 }
62 return path, nil
63 }
64 }
65 return "", &Error{file, ErrNotFound}
66 }
67
68
69
70 func lookExtensions(path, dir string) (string, error) {
71 return path, nil
72 }
73
View as plain text