summaryrefslogtreecommitdiff
path: root/src/internal/syscall/unix/nonblocking_wasip1.go
blob: 208db28c3efdb119dae82774ed206878445eb817 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright 2023 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.

//go:build wasip1

package unix

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

func IsNonblock(fd int) (nonblocking bool, err error) {
	flags, e1 := fd_fdstat_get_flags(fd)
	if e1 != nil {
		return false, e1
	}
	return flags&syscall.FDFLAG_NONBLOCK != 0, nil
}

// This helper is implemented in the syscall package. It means we don't have
// to redefine the fd_fdstat_get host import or the fdstat struct it
// populates.
//
//go:linkname fd_fdstat_get_flags syscall.fd_fdstat_get_flags
func fd_fdstat_get_flags(fd int) (uint32, error)