github.com/AESNooper/go/src@v0.0.0-20220218095104-b56a4ab1bbbb/os/exec/internal/fdtest/exists_js.go (about)

     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 js
     6  
     7  package fdtest
     8  
     9  import (
    10  	"syscall"
    11  )
    12  
    13  // Exists returns true if fd is a valid file descriptor.
    14  func Exists(fd uintptr) bool {
    15  	var s syscall.Stat_t
    16  	err := syscall.Fstat(int(fd), &s)
    17  	return err != syscall.EBADF
    18  }