aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/os/stat_linux.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-11-01 09:37:13 -0800
committerRuss Cox <rsc@golang.org>2009-11-01 09:37:13 -0800
commita64b69da9ee267007b79fdb0c33567fdc2af37e6 (patch)
tree36912cce675188c8fd2a9a7a3507e882ebb533f4 /src/pkg/os/stat_linux.go
parent7732d80ceb1b5ea5c7a7a52c7bcf6f433a7a4d53 (diff)
downloadgo-a64b69da9ee267007b79fdb0c33567fdc2af37e6.tar.xz
os cleanup.
dir_* and stat_* are just os specific, not os+arch-specific. R=r http://go/go-review/1018010
Diffstat (limited to 'src/pkg/os/stat_linux.go')
-rw-r--r--src/pkg/os/stat_linux.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/pkg/os/stat_linux.go b/src/pkg/os/stat_linux.go
new file mode 100644
index 0000000000..fe4193a5b8
--- /dev/null
+++ b/src/pkg/os/stat_linux.go
@@ -0,0 +1,38 @@
+// 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.
+
+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 = 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 = stat.Rdev;
+ dir.Size = uint64(stat.Size);
+ dir.Blksize = uint64(stat.Blksize);
+ dir.Blocks = uint64(stat.Blocks);
+ dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim));
+ dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim));
+ dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim));
+ 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;
+}