Browse Source

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 <bradfitz@golang.org>
Philip Brown 7 years ago
parent
commit
1d206c9fa8
3 changed files with 12 additions and 0 deletions
  1. 6 0
      unix/fcntl.go
  2. 0 0
      unix/fcntl_linux_32bit.go
  3. 6 0
      unix/syscall_solaris.go

+ 6 - 0
unix/flock.go → 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)))

+ 0 - 0
unix/flock_linux_32bit.go → unix/fcntl_linux_32bit.go


+ 6 - 0
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)