src/os/exec/internal/fdtest/exists_plan9.go
raw| 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 | |
| 5 | //go:build plan9 |
| 6 | |
| 7 | package fdtest |
| 8 | |
| 9 | import ( |
| 10 | "syscall" |
| 11 | ) |
| 12 | |
| 13 | const errBadFd = syscall.ErrorString("fd out of range or not open") |
| 14 | |
| 15 | // Exists returns true if fd is a valid file descriptor. |
| 16 | func Exists(fd uintptr) bool { |
| 17 | var buf [1]byte |
| 18 | _, err := syscall.Fstat(int(fd), buf[:]) |
| 19 | return err != errBadFd |
| 20 | } |