tmpfile_others.go 376 B

1234567891011121314151617181920212223242526
  1. //go:build !linux
  2. // License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
  3. package utils
  4. import (
  5. "fmt"
  6. "os"
  7. )
  8. var _ = fmt.Print
  9. func CreateAnonymousTemp(dir string) (*os.File, error) {
  10. f, err := os.CreateTemp(dir, "")
  11. if err != nil {
  12. return nil, err
  13. }
  14. err = os.Remove(f.Name())
  15. if err != nil {
  16. f.Close()
  17. return nil, err
  18. }
  19. return f, err
  20. }