PR c++/85515
[official-gcc.git] / libgo / go / os / stat_nacl.go
blob0c53f2faa43781337abaf22be54d7b941460f7c0
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.
5 package os
7 import (
8 "syscall"
9 "time"
12 func fillFileStatFromSys(fs *fileStat, name string) {
13 fs.name = basename(name)
14 fs.size = fs.sys.Size
15 fs.modTime = timespecToTime(fs.sys.Mtime, fs.sys.MtimeNsec)
16 fs.mode = FileMode(fs.sys.Mode & 0777)
17 switch fs.sys.Mode & syscall.S_IFMT {
18 case syscall.S_IFBLK:
19 fs.mode |= ModeDevice
20 case syscall.S_IFCHR:
21 fs.mode |= ModeDevice | ModeCharDevice
22 case syscall.S_IFDIR:
23 fs.mode |= ModeDir
24 case syscall.S_IFIFO:
25 fs.mode |= ModeNamedPipe
26 case syscall.S_IFLNK:
27 fs.mode |= ModeSymlink
28 case syscall.S_IFREG:
29 // nothing to do
30 case syscall.S_IFSOCK:
31 fs.mode |= ModeSocket
33 if fs.sys.Mode&syscall.S_ISGID != 0 {
34 fs.mode |= ModeSetgid
36 if fs.sys.Mode&syscall.S_ISUID != 0 {
37 fs.mode |= ModeSetuid
39 if fs.sys.Mode&syscall.S_ISVTX != 0 {
40 fs.mode |= ModeSticky
44 func timespecToTime(sec, nsec int64) time.Time {
45 return time.Unix(sec, nsec)
48 // For testing.
49 func atime(fi FileInfo) time.Time {
50 st := fi.Sys().(*syscall.Stat_t)
51 return timespecToTime(st.Atime, st.AtimeNsec)