From: Tobias Klauser Date: Wed, 27 Sep 2023 07:03:11 +0000 (+0200) Subject: internal/syscall/unix: implement Eaccess on freebsd X-Git-Tag: go1.22rc1~733 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1176052bb40378272cfbe83d873b65fcc2ed8502;p=gostls13.git internal/syscall/unix: implement Eaccess on freebsd 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 TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills Auto-Submit: Tobias Klauser Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- diff --git a/src/internal/syscall/unix/at_sysnum_freebsd.go b/src/internal/syscall/unix/at_sysnum_freebsd.go index 9cd5da6ce3..f74961d508 100644 --- a/src/internal/syscall/unix/at_sysnum_freebsd.go +++ b/src/internal/syscall/unix/at_sysnum_freebsd.go @@ -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 index 0000000000..f2514c0a84 --- /dev/null +++ b/src/internal/syscall/unix/eaccess_freebsd.go @@ -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) +} diff --git a/src/internal/syscall/unix/eaccess_other.go b/src/internal/syscall/unix/eaccess_other.go index 23be118297..4fa2265900 100644 --- a/src/internal/syscall/unix/eaccess_other.go +++ b/src/internal/syscall/unix/eaccess_other.go @@ -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