From 6beb45e5b74aa465136687f00f2b5a51bee90395 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Wed, 6 Dec 2017 00:18:38 +0100 Subject: syscallcompat: add Darwin version of unix2syscall The "Atim" field is called "Atimespec" on Darwin, same for Mtim and Ctim. --- internal/syscallcompat/unix2syscall.go | 28 --------------------------- internal/syscallcompat/unix2syscall_darwin.go | 26 +++++++++++++++++++++++++ internal/syscallcompat/unix2syscall_linux.go | 28 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 28 deletions(-) delete mode 100644 internal/syscallcompat/unix2syscall.go create mode 100644 internal/syscallcompat/unix2syscall_darwin.go create mode 100644 internal/syscallcompat/unix2syscall_linux.go diff --git a/internal/syscallcompat/unix2syscall.go b/internal/syscallcompat/unix2syscall.go deleted file mode 100644 index 3162025..0000000 --- a/internal/syscallcompat/unix2syscall.go +++ /dev/null @@ -1,28 +0,0 @@ -package syscallcompat - -import ( - "syscall" - - "golang.org/x/sys/unix" -) - -// Unix2syscall converts a unix.Stat_t struct to a syscall.Stat_t struct. -// A direct cast does not work because the padding is named differently in -// unix.Stat_t for some reason ("X__unused" in syscall, "_" in unix). -func Unix2syscall(u unix.Stat_t) syscall.Stat_t { - return syscall.Stat_t{ - Dev: u.Dev, - Ino: u.Ino, - Nlink: u.Nlink, - Mode: u.Mode, - Uid: u.Uid, - Gid: u.Gid, - Rdev: u.Rdev, - Size: u.Size, - Blksize: u.Blksize, - Blocks: u.Blocks, - Atim: syscall.Timespec(u.Atim), - Mtim: syscall.Timespec(u.Mtim), - Ctim: syscall.Timespec(u.Ctim), - } -} diff --git a/internal/syscallcompat/unix2syscall_darwin.go b/internal/syscallcompat/unix2syscall_darwin.go new file mode 100644 index 0000000..93d0ab3 --- /dev/null +++ b/internal/syscallcompat/unix2syscall_darwin.go @@ -0,0 +1,26 @@ +package syscallcompat + +import ( + "syscall" + + "golang.org/x/sys/unix" +) + +// Unix2syscall converts a unix.Stat_t struct to a syscall.Stat_t struct. +func Unix2syscall(u unix.Stat_t) syscall.Stat_t { + return syscall.Stat_t{ + Dev: u.Dev, + Ino: u.Ino, + Nlink: u.Nlink, + Mode: u.Mode, + Uid: u.Uid, + Gid: u.Gid, + Rdev: u.Rdev, + Size: u.Size, + Blksize: u.Blksize, + Blocks: u.Blocks, + Atimespec: syscall.Timespec(u.Atimespec), + Mtimespec: syscall.Timespec(u.Mtimespec), + Ctimespec: syscall.Timespec(u.Ctimespec), + } +} diff --git a/internal/syscallcompat/unix2syscall_linux.go b/internal/syscallcompat/unix2syscall_linux.go new file mode 100644 index 0000000..3162025 --- /dev/null +++ b/internal/syscallcompat/unix2syscall_linux.go @@ -0,0 +1,28 @@ +package syscallcompat + +import ( + "syscall" + + "golang.org/x/sys/unix" +) + +// Unix2syscall converts a unix.Stat_t struct to a syscall.Stat_t struct. +// A direct cast does not work because the padding is named differently in +// unix.Stat_t for some reason ("X__unused" in syscall, "_" in unix). +func Unix2syscall(u unix.Stat_t) syscall.Stat_t { + return syscall.Stat_t{ + Dev: u.Dev, + Ino: u.Ino, + Nlink: u.Nlink, + Mode: u.Mode, + Uid: u.Uid, + Gid: u.Gid, + Rdev: u.Rdev, + Size: u.Size, + Blksize: u.Blksize, + Blocks: u.Blocks, + Atim: syscall.Timespec(u.Atim), + Mtim: syscall.Timespec(u.Mtim), + Ctim: syscall.Timespec(u.Ctim), + } +} -- cgit v1.2.3