diff --git a/runtime/internal/clite/os/os.go b/runtime/internal/clite/os/os.go index cdfd5f66..df9a0b17 100644 --- a/runtime/internal/clite/os/os.go +++ b/runtime/internal/clite/os/os.go @@ -87,12 +87,6 @@ func Remove(path *c.Char) c.Int //go:linkname Rename C.rename func Rename(oldpath *c.Char, newpath *c.Char) c.Int -//go:linkname Stat C.stat -func Stat(path *c.Char, buf *StatT) c.Int - -//go:linkname Lstat C.lstat -func Lstat(path *c.Char, buf *StatT) c.Int - //go:linkname Truncate C.truncate func Truncate(path *c.Char, length OffT) c.Int @@ -285,7 +279,7 @@ func Exit(c.Int) // ----------------------------------------------------------------------------- -// Upon successful completion, the value 0 is returned; otherwise the value -1 +// Upon successful completion, the value 0 is returned; otherwise the value -1 // is returned and the global variable errno is set to indicate the error. // //go:linkname Sysctl C.sysctl diff --git a/runtime/internal/clite/os/stat.go b/runtime/internal/clite/os/stat.go new file mode 100644 index 00000000..2fc00ca6 --- /dev/null +++ b/runtime/internal/clite/os/stat.go @@ -0,0 +1,16 @@ +//go:build !darwin +// +build !darwin + +package os + +import ( + _ "unsafe" + + c "github.com/goplus/llgo/runtime/internal/clite" +) + +//go:linkname Stat C.stat +func Stat(path *c.Char, buf *StatT) c.Int + +//go:linkname Lstat C.lstat +func Lstat(path *c.Char, buf *StatT) c.Int diff --git a/runtime/internal/clite/os/stat_darwin.go b/runtime/internal/clite/os/stat_darwin.go new file mode 100644 index 00000000..0017571e --- /dev/null +++ b/runtime/internal/clite/os/stat_darwin.go @@ -0,0 +1,13 @@ +package os + +import ( + _ "unsafe" + + c "github.com/goplus/llgo/runtime/internal/clite" +) + +//go:linkname Stat C.stat64 +func Stat(path *c.Char, buf *StatT) c.Int + +//go:linkname Lstat C.lstat64 +func Lstat(path *c.Char, buf *StatT) c.Int diff --git a/runtime/internal/lib/os/stat_unix.go b/runtime/internal/lib/os/stat_unix.go index b55f2341..2ef98d2c 100644 --- a/runtime/internal/lib/os/stat_unix.go +++ b/runtime/internal/lib/os/stat_unix.go @@ -35,6 +35,7 @@ func statNolog(name string) (FileInfo, error) { if err != nil { return nil, &PathError{Op: "stat", Path: name, Err: err} } + fillFileStatFromSys(&fs, name) return &fs, nil } @@ -47,5 +48,6 @@ func lstatNolog(name string) (FileInfo, error) { if err != nil { return nil, &PathError{Op: "lstat", Path: name, Err: err} } + fillFileStatFromSys(&fs, name) return &fs, nil }