Black Lives Matter. Support the Equal Justice Initiative.

Source file src/os/stat_unix.go

Documentation: os

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

View as plain text