files.go 250 B

12345678910111213141516
  1. //go:build linux || darwin
  2. // +build linux darwin
  3. package fs
  4. import (
  5. "os"
  6. "syscall"
  7. )
  8. // CloseOnExec makes sure closing the file on process forking.
  9. func CloseOnExec(file *os.File) {
  10. if file != nil {
  11. syscall.CloseOnExec(int(file.Fd()))
  12. }
  13. }