aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat
diff options
context:
space:
mode:
Diffstat (limited to 'internal/syscallcompat')
-rw-r--r--internal/syscallcompat/sys_darwin.go18
-rw-r--r--internal/syscallcompat/sys_linux.go4
2 files changed, 22 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.
diff --git a/internal/syscallcompat/sys_linux.go b/internal/syscallcompat/sys_linux.go
index e12d100..ded5d17 100644
--- a/internal/syscallcompat/sys_linux.go
+++ b/internal/syscallcompat/sys_linux.go
@@ -48,3 +48,7 @@ func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error) {
return syscall.Renameat(olddirfd, oldpath, newdirfd, newpath)
}
+
+func Unlinkat(dirfd int, path string) error {
+ return syscall.Unlinkat(dirfd, path)
+}