Home | History | Annotate | Download | only in 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 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
      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 	if f == nil {
     17 		return nil, ErrInvalid
     18 	}
     19 	var fs fileStat
     20 	err := syscall.Fstat(f.fd, &fs.sys)
     21 	if err != nil {
     22 		return nil, &PathError{"stat", f.name, err}
     23 	}
     24 	fillFileStatFromSys(&fs, f.name)
     25 	return &fs, nil
     26 }
     27 
     28 // Stat returns a FileInfo describing the named file.
     29 // If there is an error, it will be of type *PathError.
     30 func Stat(name string) (FileInfo, error) {
     31 	var fs fileStat
     32 	err := syscall.Stat(name, &fs.sys)
     33 	if err != nil {
     34 		return nil, &PathError{"stat", name, err}
     35 	}
     36 	fillFileStatFromSys(&fs, name)
     37 	return &fs, nil
     38 }
     39 
     40 // Lstat returns a FileInfo describing the named file.
     41 // If the file is a symbolic link, the returned FileInfo
     42 // describes the symbolic link. Lstat makes no attempt to follow the link.
     43 // If there is an error, it will be of type *PathError.
     44 func Lstat(name string) (FileInfo, error) {
     45 	var fs fileStat
     46 	err := syscall.Lstat(name, &fs.sys)
     47 	if err != nil {
     48 		return nil, &PathError{"lstat", name, err}
     49 	}
     50 	fillFileStatFromSys(&fs, name)
     51 	return &fs, nil
     52 }
     53