summaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_darwin.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-07-03 20:17:40 +0200
committerJakob Unterwurzacher2016-07-03 20:17:40 +0200
commitd8524c73696392c7e895e6b3fe4c7e120d7296f7 (patch)
treefa071f1ffb9946bfdd152c2ab7c5e9496b3ea52e /internal/syscallcompat/sys_darwin.go
parent1d7728959c2120cd9bc0f1280cbdd1daccaa497c (diff)
syscallcompat: OSX: add Unlinkat wrapper
Also, replace remaining naked syscall.Openat calls.
Diffstat (limited to 'internal/syscallcompat/sys_darwin.go')
-rw-r--r--internal/syscallcompat/sys_darwin.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/syscallcompat/sys_darwin.go b/internal/syscallcompat/sys_darwin.go
index 7d39484..6300317 100644
--- a/internal/syscallcompat/sys_darwin.go
+++ b/internal/syscallcompat/sys_darwin.go
@@ -69,6 +69,24 @@ func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err e
return syscall.Rename(oldpath, newpath)
}
+// Poor man's Unlinkat
+func Unlinkat(dirfd int, path string) (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.Unlink(path)
+}
+
// 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.