Blame vendor/golang.org/x/sys/unix/fcntl.go
|
Packit |
63bb0d |
// Copyright 2014 The Go Authors. All rights reserved.
|
|
Packit |
63bb0d |
// Use of this source code is governed by a BSD-style
|
|
Packit |
63bb0d |
// license that can be found in the LICENSE file.
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// +build dragonfly freebsd linux netbsd openbsd
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
package unix
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
import "unsafe"
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// fcntl64Syscall is usually SYS_FCNTL, but is overridden on 32-bit Linux
|
|
Packit |
63bb0d |
// systems by fcntl_linux_32bit.go to be SYS_FCNTL64.
|
|
Packit |
63bb0d |
var fcntl64Syscall uintptr = SYS_FCNTL
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
func fcntl(fd int, cmd, arg int) (int, error) {
|
|
Packit |
63bb0d |
valptr, _, errno := Syscall(fcntl64Syscall, uintptr(fd), uintptr(cmd), uintptr(arg))
|
|
Packit |
63bb0d |
var err error
|
|
Packit |
63bb0d |
if errno != 0 {
|
|
Packit |
63bb0d |
err = errno
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
return int(valptr), err
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// FcntlInt performs a fcntl syscall on fd with the provided command and argument.
|
|
Packit |
63bb0d |
func FcntlInt(fd uintptr, cmd, arg int) (int, error) {
|
|
Packit |
63bb0d |
return fcntl(int(fd), cmd, arg)
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
|
|
Packit |
63bb0d |
// FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
|
|
Packit |
63bb0d |
func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error {
|
|
Packit |
63bb0d |
_, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk)))
|
|
Packit |
63bb0d |
if errno == 0 {
|
|
Packit |
63bb0d |
return nil
|
|
Packit |
63bb0d |
}
|
|
Packit |
63bb0d |
return errno
|
|
Packit |
63bb0d |
}
|