OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [os/] [exec/] [lp_windows.go] - Blame information for rev 774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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.
4
 
5
package exec
6
 
7
import (
8
        "errors"
9
        "os"
10
        "strings"
11
)
12
 
13
// ErrNotFound is the error resulting if a path search failed to find an executable file.
14
var ErrNotFound = errors.New("executable file not found in %PATH%")
15
 
16
func chkStat(file string) error {
17
        d, err := os.Stat(file)
18
        if err != nil {
19
                return err
20
        }
21
        if d.IsDir() {
22
                return os.EPERM
23
        }
24
        return nil
25
}
26
 
27
func findExecutable(file string, exts []string) (string, error) {
28
        if len(exts) == 0 {
29
                return file, chkStat(file)
30
        }
31
        f := strings.ToLower(file)
32
        for _, e := range exts {
33
                if strings.HasSuffix(f, e) {
34
                        return file, chkStat(file)
35
                }
36
        }
37
        for _, e := range exts {
38
                if f := file + e; chkStat(f) == nil {
39
                        return f, nil
40
                }
41
        }
42
        return ``, os.ENOENT
43
}
44
 
45
// LookPath searches for an executable binary named file
46
// in the directories named by the PATH environment variable.
47
// If file contains a slash, it is tried directly and the PATH is not consulted.
48
// LookPath also uses PATHEXT environment variable to match
49
// a suitable candidate.
50
func LookPath(file string) (f string, err error) {
51
        x := os.Getenv(`PATHEXT`)
52
        if x == `` {
53
                x = `.COM;.EXE;.BAT;.CMD`
54
        }
55
        exts := []string{}
56
        for _, e := range strings.Split(strings.ToLower(x), `;`) {
57
                if e == "" {
58
                        continue
59
                }
60
                if e[0] != '.' {
61
                        e = "." + e
62
                }
63
                exts = append(exts, e)
64
        }
65
        if strings.IndexAny(file, `:\/`) != -1 {
66
                if f, err = findExecutable(file, exts); err == nil {
67
                        return
68
                }
69
                return ``, &Error{file, err}
70
        }
71
        if f, err = findExecutable(`.\`+file, exts); err == nil {
72
                return
73
        }
74
        if pathenv := os.Getenv(`PATH`); pathenv != `` {
75
                for _, dir := range strings.Split(pathenv, `;`) {
76
                        if f, err = findExecutable(dir+`\`+file, exts); err == nil {
77
                                return
78
                        }
79
                }
80
        }
81
        return ``, &Error{file, ErrNotFound}
82
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.