1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
12 func chkStat(file string) bool {
13 d, err := os.Stat(file)
20 func canExec(file string, exts []string) (string, bool) {
22 return file, chkStat(file)
24 f := strings.ToLower(file)
25 for _, e := range exts {
26 if strings.HasSuffix(f, e) {
27 return file, chkStat(file)
30 for _, e := range exts {
31 if f := file + e; chkStat(f) {
38 func LookPath(file string) (string, os.Error) {
40 if x := os.Getenv(`PATHEXT`); x != `` {
41 exts = strings.Split(strings.ToLower(x), `;`, -1)
42 for i, e := range exts {
43 if e == `` || e[0] != '.' {
48 if strings.Contains(file, `\`) || strings.Contains(file, `/`) {
49 if f, ok := canExec(file, exts); ok {
52 return ``, &PathError{file}
54 if pathenv := os.Getenv(`PATH`); pathenv == `` {
55 if f, ok := canExec(`.\`+file, exts); ok {
59 for _, dir := range strings.Split(pathenv, `;`, -1) {
60 if f, ok := canExec(dir+`\`+file, exts); ok {
65 return ``, &PathError{file}