flock.go 752 B

12345678910111213141516171819202122232425
  1. // +build linux darwin freebsd openbsd netbsd dragonfly
  2. // Copyright 2014 The Go Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. // +build darwin dragonfly freebsd linux netbsd openbsd
  6. package unix
  7. import "unsafe"
  8. // fcntl64Syscall is usually SYS_FCNTL, but is overridden on 32-bit Linux
  9. // systems by flock_linux_32bit.go to be SYS_FCNTL64.
  10. var fcntl64Syscall uintptr = SYS_FCNTL
  11. // FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
  12. func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error {
  13. _, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk)))
  14. if errno == 0 {
  15. return nil
  16. }
  17. return errno
  18. }