| 1 |
// Copyright 2025 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 |
package windows |
| 6 |
|
| 7 |
import ( |
| 8 |
"syscall" |
| 9 |
"unsafe" |
| 10 |
) |
| 11 |
|
| 12 |
// IsNonblock returns whether the file descriptor fd is opened |
| 13 |
// in non-blocking mode, that is, the [windows.O_FILE_FLAG_OVERLAPPED] flag |
| 14 |
// was set when the file was opened. |
| 15 |
func IsNonblock(fd syscall.Handle) (nonblocking bool, err error) { |
| 16 |
var info FILE_MODE_INFORMATION |
| 17 |
if err := NtQueryInformationFile(syscall.Handle(fd), &IO_STATUS_BLOCK{}, unsafe.Pointer(&info), uint32(unsafe.Sizeof(info)), FileModeInformation); err != nil { |
| 18 |
return false, err |
| 19 |
} |
| 20 |
return info.Mode&(FILE_SYNCHRONOUS_IO_ALERT|FILE_SYNCHRONOUS_IO_NONALERT) == 0, nil |
| 21 |
} |