aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat/emulate.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-12-03 17:53:14 +0100
committerJakob Unterwurzacher2017-12-03 19:32:59 +0100
commite33593d30d9dee6fd6b0e7c0d01832e478815d88 (patch)
tree5070656829a7215bd4fe01404f208798cd073a2b /internal/syscallcompat/emulate.go
parent441e796e7034977c15dc9402a880ef4061b471a7 (diff)
syscallcompat: add Fstatat + emulation + test
Fstatat has recently been added to x/sys/unix. Make it available for use in gocryptfs.
Diffstat (limited to 'internal/syscallcompat/emulate.go')
-rw-r--r--internal/syscallcompat/emulate.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/syscallcompat/emulate.go b/internal/syscallcompat/emulate.go
index 96776e2..e5aeae7 100644
--- a/internal/syscallcompat/emulate.go
+++ b/internal/syscallcompat/emulate.go
@@ -210,3 +210,23 @@ func emulateMkdirat(dirfd int, path string, mode uint32) (err error) {
}
return syscall.Mkdir(path, mode)
}
+
+// emulateFstatat emulates the syscall for platforms that don't have it
+// in the kernel (darwin).
+func emulateFstatat(dirfd int, path string, stat *unix.Stat_t, flags int) (err error) {
+ if !filepath.IsAbs(path) {
+ chdirMutex.Lock()
+ defer chdirMutex.Unlock()
+ cwd, err := syscall.Open(".", syscall.O_RDONLY, 0)
+ if err != nil {
+ return err
+ }
+ defer syscall.Close(cwd)
+ err = syscall.Fchdir(dirfd)
+ if err != nil {
+ return err
+ }
+ defer syscall.Fchdir(cwd)
+ }
+ return unix.Lstat(path, stat)
+}