stat_unix.mx raw
1 //go:build darwin || (linux && !baremetal && !wasm_unknown && !nintendoswitch) || wasip1 || wasip2
2
3 // Copyright 2016 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package os
8
9 import (
10 "syscall"
11 )
12
13 // Stat returns the FileInfo structure describing file.
14 // If there is an error, it will be of type *PathError.
15 func (f *File) Stat() (FileInfo, error) {
16 var fs fileStat
17 err := ignoringEINTR(func() error {
18 return syscall.Fstat(int(f.handle.(unixFileHandle)), &fs.sys)
19 })
20 if err != nil {
21 return nil, &PathError{Op: "fstat", Path: f.name, Err: err}
22 }
23 fillFileStatFromSys(&fs, f.name)
24 return &fs, nil
25 }
26
27 // statNolog stats a file with no test logging.
28 func statNolog(name string) (FileInfo, error) {
29 var fs fileStat
30 err := ignoringEINTR(func() error {
31 return handleSyscallError(syscall.Stat(name, &fs.sys))
32 })
33 if err != nil {
34 return nil, &PathError{Op: "stat", Path: name, Err: err}
35 }
36 fillFileStatFromSys(&fs, name)
37 return &fs, nil
38 }
39
40 // lstatNolog lstats a file with no test logging.
41 func lstatNolog(name string) (FileInfo, error) {
42 var fs fileStat
43 err := ignoringEINTR(func() error {
44 return handleSyscallError(syscall.Lstat(name, &fs.sys))
45 })
46 if err != nil {
47 return nil, &PathError{Op: "lstat", Path: name, Err: err}
48 }
49 fillFileStatFromSys(&fs, name)
50 return &fs, nil
51 }
52