You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fcntl.go 1.0KB

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2014 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build dragonfly || freebsd || linux || netbsd
  5. package unix
  6. import "unsafe"
  7. // fcntl64Syscall is usually SYS_FCNTL, but is overridden on 32-bit Linux
  8. // systems by fcntl_linux_32bit.go to be SYS_FCNTL64.
  9. var fcntl64Syscall uintptr = SYS_FCNTL
  10. func fcntl(fd int, cmd, arg int) (int, error) {
  11. valptr, _, errno := Syscall(fcntl64Syscall, uintptr(fd), uintptr(cmd), uintptr(arg))
  12. var err error
  13. if errno != 0 {
  14. err = errno
  15. }
  16. return int(valptr), err
  17. }
  18. // FcntlInt performs a fcntl syscall on fd with the provided command and argument.
  19. func FcntlInt(fd uintptr, cmd, arg int) (int, error) {
  20. return fcntl(int(fd), cmd, arg)
  21. }
  22. // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
  23. func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error {
  24. _, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk)))
  25. if errno == 0 {
  26. return nil
  27. }
  28. return errno
  29. }