src/{syscall, os}: add File.Stat, with smoke test

This is File.Stat from https://github.com/tinygo-org/tinygo/pull/2371,
plus the windows bits,
plus a smoke test more or less from upstream,
all pulled together and rebased by dkegel-fastly.
This commit is contained in:
Damian Gryski
2021-12-09 18:53:51 -08:00
committed by Ron Evans
parent b85cb55aab
commit 322abf6d22
7 changed files with 108 additions and 5 deletions
+14
View File
@@ -15,6 +15,20 @@ func (f *File) Sync() error {
return ErrNotImplemented
}
// Stat returns the FileInfo structure describing file.
// If there is an error, it will be of type *PathError.
func (f *File) Stat() (FileInfo, error) {
var fs fileStat
err := ignoringEINTR(func() error {
return syscall.Fstat(int(f.handle.(unixFileHandle)), &fs.sys)
})
if err != nil {
return nil, &PathError{Op: "fstat", Path: f.name, Err: err}
}
fillFileStatFromSys(&fs, f.name)
return &fs, nil
}
// statNolog stats a file with no test logging.
func statNolog(name string) (FileInfo, error) {
var fs fileStat