...

Source file src/os/exec/internal/fdtest/exists_unix.go

Documentation: os/exec/internal/fdtest

     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 unix || wasm
     6  
     7  // Package fdtest provides test helpers for working with file descriptors across exec.
     8  package fdtest
     9  
    10  import (
    11  	"syscall"
    12  )
    13  
    14  // Exists returns true if fd is a valid file descriptor.
    15  func Exists(fd uintptr) bool {
    16  	var s syscall.Stat_t
    17  	err := syscall.Fstat(int(fd), &s)
    18  	return err != syscall.EBADF
    19  }
    20  

View as plain text