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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [os/] [exec/] [lp_plan9.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 2011 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 findExecutable(file string) error {
17
        d, err := os.Stat(file)
18
        if err != nil {
19
                return err
20
        }
21
        if m := d.Mode(); !m.IsDir() && m&0111 != 0 {
22
                return nil
23
        }
24
        return os.EPERM
25
}
26
 
27
// LookPath searches for an executable binary named file
28
// in the directories named by the path environment variable.
29
// If file begins with "/", "#", "./", or "../", it is tried
30
// directly and the path is not consulted.
31
func LookPath(file string) (string, error) {
32
        // skip the path lookup for these prefixes
33
        skip := []string{"/", "#", "./", "../"}
34
 
35
        for _, p := range skip {
36
                if strings.HasPrefix(file, p) {
37
                        err := findExecutable(file)
38
                        if err == nil {
39
                                return file, nil
40
                        }
41
                        return "", &Error{file, err}
42
                }
43
        }
44
 
45
        path := os.Getenv("path")
46
        for _, dir := range strings.Split(path, "\000") {
47
                if err := findExecutable(dir + "/" + file); err == nil {
48
                        return dir + "/" + file, nil
49
                }
50
        }
51
        return "", &Error{file, ErrNotFound}
52
}

powered by: WebSVN 2.1.0

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