LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package exec | 5 package exec |
6 | 6 |
7 import ( | 7 import ( |
8 "os" | 8 "os" |
9 "strings" | 9 "strings" |
10 ) | 10 ) |
11 | 11 |
12 // ErrNotFound is the error resulting if a path search failed to find an executa
ble file. | 12 // ErrNotFound is the error resulting if a path search failed to find an executa
ble file. |
13 var ErrNotFound = os.ErrorString("executable file not found in $PATH") | 13 var ErrNotFound = os.NewError("executable file not found in $PATH") |
14 | 14 |
15 func findExecutable(file string) os.Error { | 15 func findExecutable(file string) os.Error { |
16 d, err := os.Stat(file) | 16 d, err := os.Stat(file) |
17 if err != nil { | 17 if err != nil { |
18 return err | 18 return err |
19 } | 19 } |
20 if d.IsRegular() && d.Permission()&0111 != 0 { | 20 if d.IsRegular() && d.Permission()&0111 != 0 { |
21 return nil | 21 return nil |
22 } | 22 } |
23 return os.EPERM | 23 return os.EPERM |
(...skipping 19 matching lines...) Expand all Loading... |
43 if dir == "" { | 43 if dir == "" { |
44 // Unix shell semantics: path element "" means "." | 44 // Unix shell semantics: path element "" means "." |
45 dir = "." | 45 dir = "." |
46 } | 46 } |
47 if err := findExecutable(dir + "/" + file); err == nil { | 47 if err := findExecutable(dir + "/" + file); err == nil { |
48 return dir + "/" + file, nil | 48 return dir + "/" + file, nil |
49 } | 49 } |
50 } | 50 } |
51 return "", &Error{file, ErrNotFound} | 51 return "", &Error{file, ErrNotFound} |
52 } | 52 } |
LEFT | RIGHT |