github.com/zxy12/go_duplicate_112_new@v0.0.0-20200807091221-747231827200/src/os/stat_nacljs.go (about)

     1  // Copyright 2009 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 js,wasm nacl
     6  
     7  package os
     8  
     9  import (
    10  	"syscall"
    11  	"time"
    12  )
    13  
    14  func fillFileStatFromSys(fs *fileStat, name string) {
    15  	fs.name = basename(name)
    16  	fs.size = fs.sys.Size
    17  	fs.modTime = timespecToTime(fs.sys.Mtime, fs.sys.MtimeNsec)
    18  	fs.mode = FileMode(fs.sys.Mode & 0777)
    19  	switch fs.sys.Mode & syscall.S_IFMT {
    20  	case syscall.S_IFBLK:
    21  		fs.mode |= ModeDevice
    22  	case syscall.S_IFCHR:
    23  		fs.mode |= ModeDevice | ModeCharDevice
    24  	case syscall.S_IFDIR:
    25  		fs.mode |= ModeDir
    26  	case syscall.S_IFIFO:
    27  		fs.mode |= ModeNamedPipe
    28  	case syscall.S_IFLNK:
    29  		fs.mode |= ModeSymlink
    30  	case syscall.S_IFREG:
    31  		// nothing to do
    32  	case syscall.S_IFSOCK:
    33  		fs.mode |= ModeSocket
    34  	}
    35  	if fs.sys.Mode&syscall.S_ISGID != 0 {
    36  		fs.mode |= ModeSetgid
    37  	}
    38  	if fs.sys.Mode&syscall.S_ISUID != 0 {
    39  		fs.mode |= ModeSetuid
    40  	}
    41  	if fs.sys.Mode&syscall.S_ISVTX != 0 {
    42  		fs.mode |= ModeSticky
    43  	}
    44  }
    45  
    46  func timespecToTime(sec, nsec int64) time.Time {
    47  	return time.Unix(sec, nsec)
    48  }
    49  
    50  // For testing.
    51  func atime(fi FileInfo) time.Time {
    52  	st := fi.Sys().(*syscall.Stat_t)
    53  	return timespecToTime(st.Atime, st.AtimeNsec)
    54  }