From 1d206c9fa8975fb4cf00df1dc8bf3283dc24ba0e Mon Sep 17 00:00:00 2001 From: Philip Brown Date: Wed, 4 Apr 2018 17:59:11 +0000 Subject: [PATCH] unix: add FcntlInt Fixes golang/go#24649 Fixes golang/go#24677 Change-Id: I3faa74ab68e093a097c3f2a8ec7c054431bdfb3f Reviewed-on: https://go-review.googlesource.com/104736 Reviewed-by: Brad Fitzpatrick --- unix/{flock.go => fcntl.go} | 6 ++++++ unix/{flock_linux_32bit.go => fcntl_linux_32bit.go} | 0 unix/syscall_solaris.go | 6 ++++++ 3 files changed, 12 insertions(+) rename unix/{flock.go => fcntl.go} (74%) rename unix/{flock_linux_32bit.go => fcntl_linux_32bit.go} (100%) diff --git a/unix/flock.go b/unix/fcntl.go similarity index 74% rename from unix/flock.go rename to unix/fcntl.go index 2994ce75..0c58c7e1 100644 --- a/unix/flock.go +++ b/unix/fcntl.go @@ -12,6 +12,12 @@ import "unsafe" // systems by flock_linux_32bit.go to be SYS_FCNTL64. var fcntl64Syscall uintptr = SYS_FCNTL +// FcntlInt performs a fcntl syscall on fd with the provided command and argument. +func FcntlInt(fd uintptr, cmd, arg int) (int, error) { + valptr, _, err := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(arg)) + return int(valptr), err +} + // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command. func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error { _, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk))) diff --git a/unix/flock_linux_32bit.go b/unix/fcntl_linux_32bit.go similarity index 100% rename from unix/flock_linux_32bit.go rename to unix/fcntl_linux_32bit.go diff --git a/unix/syscall_solaris.go b/unix/syscall_solaris.go index 76fe8e77..b7629529 100644 --- a/unix/syscall_solaris.go +++ b/unix/syscall_solaris.go @@ -312,6 +312,12 @@ func UtimesNanoAt(dirfd int, path string, ts []Timespec, flags int) error { //sys fcntl(fd int, cmd int, arg int) (val int, err error) +// FcntlInt performs a fcntl syscall on fd with the provided command and argument. +func FcntlInt(fd uintptr, cmd, arg int) (int, error) { + valptr, _, err := sysvicall6(uintptr(unsafe.Pointer(&procfcntl)), 3, uintptr(fd), uintptr(cmd), uintptr(arg), 0, 0, 0) + return int(valptr), err +} + // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command. func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error { _, _, e1 := sysvicall6(uintptr(unsafe.Pointer(&procfcntl)), 3, uintptr(fd), uintptr(cmd), uintptr(unsafe.Pointer(lk)), 0, 0, 0)