fcntl_syscall_test.go 665 B

1234567891011121314151617181920212223242526
  1. // Copyright 2021 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 || openbsd
  5. package net
  6. import (
  7. "syscall"
  8. )
  9. // Use a helper function to call fcntl. This is defined in C in
  10. // libgo/runtime.
  11. //extern __go_fcntl_uintptr
  12. func libc_fcntl(uintptr, uintptr, uintptr) (uintptr, uintptr)
  13. func fcntl(fd int, cmd int, arg int) (int, error) {
  14. syscall.Entersyscall()
  15. r, e := libc_fcntl(uintptr(fd), uintptr(cmd), uintptr(arg))
  16. syscall.Exitsyscall()
  17. if e != 0 {
  18. return int(r), syscall.Errno(e)
  19. }
  20. return int(r), nil
  21. }