fcntl.go 987 B

1234567891011121314151617181920212223242526272829303132
  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. // +build darwin dragonfly freebsd linux netbsd openbsd
  5. package unix
  6. import "unsafe"
  7. // fcntl64Syscall is usually SYS_FCNTL, but is overridden on 32-bit Linux
  8. // systems by flock_linux_32bit.go to be SYS_FCNTL64.
  9. var fcntl64Syscall uintptr = SYS_FCNTL
  10. // FcntlInt performs a fcntl syscall on fd with the provided command and argument.
  11. func FcntlInt(fd uintptr, cmd, arg int) (int, error) {
  12. valptr, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(arg))
  13. var err error
  14. if errno != 0 {
  15. err = errno
  16. }
  17. return int(valptr), err
  18. }
  19. // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
  20. func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error {
  21. _, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk)))
  22. if errno == 0 {
  23. return nil
  24. }
  25. return errno
  26. }