From 741bf0726e71c931af1dc1278571c280fc27970f Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 3 Jul 2016 20:21:29 +0200 Subject: syscallcompat: OSX: add Mknodat wrapper Protip: find naked *at syscalls using: git grep "syscall." | grep "at(" | grep -v syscallcompat --- internal/syscallcompat/sys_darwin.go | 18 ++++++++++++++++++ internal/syscallcompat/sys_linux.go | 4 ++++ 2 files changed, 22 insertions(+) (limited to 'internal/syscallcompat') diff --git a/internal/syscallcompat/sys_darwin.go b/internal/syscallcompat/sys_darwin.go index 6300317..852eee4 100644 --- a/internal/syscallcompat/sys_darwin.go +++ b/internal/syscallcompat/sys_darwin.go @@ -87,6 +87,24 @@ func Unlinkat(dirfd int, path string) (err error) { return syscall.Unlink(path) } +// Poor man's Mknodat +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + chdirMutex.Lock() + defer chdirMutex.Unlock() + if !filepath.IsAbs(path) { + oldWd, err := os.Getwd() + if err != nil { + return err + } + defer os.Chdir(oldWd) + } + path, err = dirfdAbs(dirfd, path) + if err != nil { + return err + } + return syscall.Mknod(path, mode, dev) +} + // dirfdAbs transforms the dirfd-relative "path" to an absolute one. If the // path is not already absolute, this function will change the working // directory. The caller has to chdir back. diff --git a/internal/syscallcompat/sys_linux.go b/internal/syscallcompat/sys_linux.go index ded5d17..81cdb15 100644 --- a/internal/syscallcompat/sys_linux.go +++ b/internal/syscallcompat/sys_linux.go @@ -52,3 +52,7 @@ func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err e func Unlinkat(dirfd int, path string) error { return syscall.Unlinkat(dirfd, path) } + +func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) { + return syscall.Mknodat(dirfd, path, mode, dev) +} -- cgit v1.2.3