demo: oslookpath; syscall.Lstat/Stat
This commit is contained in:
19
_demo/oslookpath/lookpath.go
Normal file
19
_demo/oslookpath/lookpath.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ls := "ls"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
ls = "dir"
|
||||||
|
}
|
||||||
|
lspath, _ := exec.LookPath(ls)
|
||||||
|
if lspath != "" {
|
||||||
|
ls = lspath
|
||||||
|
}
|
||||||
|
fmt.Println(ls)
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
_ "unsafe"
|
_ "unsafe"
|
||||||
|
|
||||||
"github.com/goplus/llgo/c"
|
"github.com/goplus/llgo/c"
|
||||||
|
"github.com/goplus/llgo/c/syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -40,7 +41,10 @@ type (
|
|||||||
GidT C.gid_t
|
GidT C.gid_t
|
||||||
OffT C.off_t
|
OffT C.off_t
|
||||||
DevT C.dev_t
|
DevT C.dev_t
|
||||||
StatT C.struct_stat
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
StatT = syscall.Stat_t
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:linkname Errno errno
|
//go:linkname Errno errno
|
||||||
|
|||||||
@@ -124,3 +124,21 @@ func Close(fd int) (err error) {
|
|||||||
}
|
}
|
||||||
return Errno(os.Errno)
|
return Errno(os.Errno)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Stat_t = syscall.Stat_t
|
||||||
|
|
||||||
|
func Lstat(path string, stat *Stat_t) (err error) {
|
||||||
|
ret := os.Lstat(c.AllocaCStr(path), stat)
|
||||||
|
if ret == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return Errno(os.Errno)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Stat(path string, stat *Stat_t) (err error) {
|
||||||
|
ret := os.Stat(c.AllocaCStr(path), stat)
|
||||||
|
if ret == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return Errno(os.Errno)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user