forked from snsinfu/reconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execvpe.go
37 lines (30 loc) · 748 Bytes
/
execvpe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"path/filepath"
"syscall"
)
// execvpe executes a file with given arguments and environment. It will
// search for an executable file in the given search paths if the file
// argument does not contain a path separator.
func execvpe(file string, paths, argv, envv []string) error {
if dir, _ := filepath.Split(file); dir != "" {
return syscall.Exec(file, argv, envv)
}
var err error = syscall.ENOENT
for _, base := range paths {
abspath := filepath.Join(base, file)
err = syscall.Exec(abspath, argv, envv)
if ec, ok := err.(syscall.Errno); ok {
switch ec {
case syscall.EACCES:
continue
case syscall.ENOENT:
continue
case syscall.ENOTDIR:
continue
}
}
break
}
return err
}