Source file src/os/stat_js.go

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

View as plain text