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