summaryrefslogtreecommitdiff
path: root/src/internal/syscall/unix/nonblocking.go
blob: 818e9c91a56999eb06115c6527e3f75d06cebe96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build darwin dragonfly freebsd linux netbsd openbsd solaris

package unix

import (
	"syscall"
	_ "unsafe" // for go:linkname
)

//go:linkname syscall_fcntl syscall.fcntl
func syscall_fcntl(fd int, cmd int, arg int) (val int, err error)

func IsNonblock(fd int) (nonblocking bool, err error) {
	flag, err := syscall_fcntl(fd, syscall.F_GETFL, 0)
	if err != nil {
		return false, err
	}
	return flag&syscall.O_NONBLOCK != 0, nil
}