summaryrefslogtreecommitdiff
path: root/src/pkg/os/stat_nacl_386.go
blob: 83b0d6c38c66e31bae6a38320a85fccde8ad4fda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// TODO(rsc): Once the porting dust settles, consider
// whether this file should be stat_nacl.go (and similarly
// stat_linux.go, stat_darwin.go) instead of having one copy per architecture.

// 386, Native Client

package os

import "syscall"

func isSymlink(stat *syscall.Stat_t) bool {
	return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK
}

func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
	dir.Dev = uint64(stat.Dev);
	dir.Ino = uint64(stat.Ino);
	dir.Nlink = uint64(stat.Nlink);
	dir.Mode = stat.Mode;
	dir.Uid = stat.Uid;
	dir.Gid = stat.Gid;
	dir.Rdev = uint64(stat.Rdev);
	dir.Size = uint64(stat.Size);
	dir.Blksize = uint64(stat.Blksize);
	dir.Blocks = uint64(stat.Blocks);
	dir.Atime_ns = uint64(stat.Atime)*1e9;
	dir.Mtime_ns = uint64(stat.Mtime)*1e9;
	dir.Ctime_ns = uint64(stat.Ctime)*1e9;
	for i := len(name) - 1; i >= 0; i-- {
		if name[i] == '/' {
			name = name[i+1:len(name)];
			break;
		}
	}
	dir.Name = name;
	if isSymlink(lstat) && !isSymlink(stat) {
		dir.FollowedSymlink = true;
	}
	return dir;
}