github.com/hxx258456/ccgo@v0.0.5-0.20230213014102-48b35f46f66f/internal/syscall/unix/nonblocking.go (about) 1 // Copyright 2018 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 5 //go:build dragonfly || freebsd || linux || netbsd || openbsd 6 // +build dragonfly freebsd linux netbsd openbsd 7 8 package unix 9 10 import "syscall" 11 12 // FcntlSyscall is the number for the fcntl system call. This is 13 // usually SYS_FCNTL, but can be overridden to SYS_FCNTL64. 14 var FcntlSyscall uintptr = syscall.SYS_FCNTL 15 16 func IsNonblock(fd int) (nonblocking bool, err error) { 17 flag, _, e1 := syscall.Syscall(FcntlSyscall, uintptr(fd), uintptr(syscall.F_GETFL), 0) 18 if e1 != 0 { 19 return false, e1 20 } 21 return flag&syscall.O_NONBLOCK != 0, nil 22 }