]> Cypherpunks repositories - gostls13.git/commitdiff
internal/syscall/unix: implement Eaccess on freebsd
authorTobias Klauser <tklauser@distanz.ch>
Wed, 27 Sep 2023 07:03:11 +0000 (09:03 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 28 Sep 2023 03:38:07 +0000 (03:38 +0000)
Like on linux, use faccessat(AT_FDCWD, path, mode, AT_EACCESS)

Change-Id: I98c8af5008bfa7940abffa6fcb3766254955cb08
Reviewed-on: https://go-review.googlesource.com/c/go/+/531155
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/internal/syscall/unix/at_sysnum_freebsd.go
src/internal/syscall/unix/eaccess_freebsd.go [new file with mode: 0644]
src/internal/syscall/unix/eaccess_other.go

index 9cd5da6ce32231a07ab2f5e2745e03666de422a9..f74961d508623d1bd3740601786adcab84d85bbc 100644 (file)
@@ -7,6 +7,8 @@ package unix
 import "syscall"
 
 const (
+       AT_EACCESS          = 0x100
+       AT_FDCWD            = -0x64
        AT_REMOVEDIR        = 0x800
        AT_SYMLINK_NOFOLLOW = 0x200
 
diff --git a/src/internal/syscall/unix/eaccess_freebsd.go b/src/internal/syscall/unix/eaccess_freebsd.go
new file mode 100644 (file)
index 0000000..f2514c0
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2023 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.
+
+package unix
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+func faccessat(dirfd int, path string, mode uint32, flags int) error {
+       p, err := syscall.BytePtrFromString(path)
+       if err != nil {
+               return err
+       }
+       _, _, errno := syscall.Syscall6(syscall.SYS_FACCESSAT, uintptr(dirfd), uintptr(unsafe.Pointer(p)), uintptr(mode), uintptr(flags), 0, 0)
+       if errno != 0 {
+               return errno
+       }
+       return err
+}
+
+func Eaccess(path string, mode uint32) error {
+       return faccessat(AT_FDCWD, path, mode, AT_EACCESS)
+}
index 23be11829755bb64c05398aa8ba04f51e03fc43c..4fa2265900f9db9221f31d2f4ed8cd8d741df2fe 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build unix && !linux
+//go:build unix && !freebsd && !linux
 
 package unix