1
0
mirror of https://github.com/golang/go synced 2024-11-22 04:34:39 -07:00

syscall, internal/syscall/unix: add Openat support for wasip1

The syscall package is mostly frozen, but wasip1 file syscall
support was added to syscall and the Open and Openat
implementations overlap. Implement Openat in syscall for
overall simplicity.

We already have syscall.Openat for some platforms, so this
doesn't add any new functions to syscall.

For #67002

Change-Id: Ia34b12ef11fc7a3b7832e07b3546a760c23efe5b
Reviewed-on: https://go-review.googlesource.com/c/go/+/617378
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
Damien Neil 2024-10-04 14:30:31 -07:00
parent 96db8cc49e
commit df97215a34
3 changed files with 18 additions and 1 deletions

View File

@ -19,6 +19,10 @@ const (
UTIME_OMIT = -0x2
)
func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
return syscall.Openat(dirfd, path, flags, perm)
}
func Readlinkat(dirfd int, path string, buf []byte) (int, error) {
var nwritten size
errno := path_readlink(

View File

@ -520,7 +520,14 @@ func Open(path string, openmode int, perm uint32) (int, error) {
return -1, EINVAL
}
dirFd, pathPtr, pathLen := preparePath(path)
return openat(dirFd, pathPtr, pathLen, openmode, perm)
}
func Openat(dirFd int, path string, openmode int, perm uint32) (int, error) {
return openat(int32(dirFd), stringPointer(path), size(len(path)), openmode, perm)
}
func openat(dirFd int32, pathPtr unsafe.Pointer, pathLen size, openmode int, perm uint32) (int, error) {
var oflags oflags
if (openmode & O_CREATE) != 0 {
oflags |= OFLAG_CREATE
@ -558,10 +565,15 @@ func Open(path string, openmode int, perm uint32) (int, error) {
fdflags |= FDFLAG_SYNC
}
var lflags lookupflags
if openmode&O_NOFOLLOW == 0 {
lflags = LOOKUP_SYMLINK_FOLLOW
}
var fd int32
errno := path_open(
dirFd,
LOOKUP_SYMLINK_FOLLOW,
lflags,
pathPtr,
pathLen,
oflags,

View File

@ -223,6 +223,7 @@ const (
O_EXCL = 0200
O_SYNC = 010000
O_DIRECTORY = 020000
O_NOFOLLOW = 0400
O_CLOEXEC = 0
)