sys.go 708 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package sysx
  2. import (
  3. "syscall"
  4. "unsafe"
  5. )
  6. var _zero uintptr
  7. // use is a no-op, but the compiler cannot see that it is.
  8. // Calling use(p) ensures that p is kept live until that point.
  9. //go:noescape
  10. func use(p unsafe.Pointer)
  11. // Do the interface allocations only once for common
  12. // Errno values.
  13. var (
  14. errEAGAIN error = syscall.EAGAIN
  15. errEINVAL error = syscall.EINVAL
  16. errENOENT error = syscall.ENOENT
  17. )
  18. // errnoErr returns common boxed Errno values, to prevent
  19. // allocations at runtime.
  20. func errnoErr(e syscall.Errno) error {
  21. switch e {
  22. case 0:
  23. return nil
  24. case syscall.EAGAIN:
  25. return errEAGAIN
  26. case syscall.EINVAL:
  27. return errEINVAL
  28. case syscall.ENOENT:
  29. return errENOENT
  30. }
  31. return e
  32. }