mirror of
https://github.com/golang/go.git
synced 2025-05-08 00:53:07 +00:00
Follow CL 146020 and enable RemoveAll based on Unlinkat and Openat on freebsd. Since the layout of syscall.Stat_t changes in FreeBSD 12, Fstatat needs a compatibility wrapper akin to Fstatat in x/sys/unix. See CL 138595 and CL 136816 for details. Updates #27029 Change-Id: I8851a5b7fa658eaa6e69a1693150b16d9a68f36a Reviewed-on: https://go-review.googlesource.com/c/146597 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Yuval Pavel Zholkover <paulzhol@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build linux darwin openbsd netbsd dragonfly
|
|
|
|
package unix
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
func Unlinkat(dirfd int, path string, flags int) error {
|
|
var p *byte
|
|
p, err := syscall.BytePtrFromString(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, _, errno := syscall.Syscall(unlinkatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags))
|
|
if errno != 0 {
|
|
return errno
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
|
|
var p *byte
|
|
p, err := syscall.BytePtrFromString(path)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
fd, _, errno := syscall.Syscall6(openatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(flags), uintptr(perm), 0, 0)
|
|
if errno != 0 {
|
|
return 0, errno
|
|
}
|
|
|
|
return int(fd), nil
|
|
}
|
|
|
|
func Fstatat(dirfd int, path string, stat *syscall.Stat_t, flags int) error {
|
|
var p *byte
|
|
p, err := syscall.BytePtrFromString(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, _, errno := syscall.Syscall6(fstatatTrap, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(unsafe.Pointer(stat)), uintptr(flags), 0, 0)
|
|
if errno != 0 {
|
|
return errno
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|