zsyscall_windows.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Code generated by 'go generate'; DO NOT EDIT.
  2. package atomicfile
  3. import (
  4. "syscall"
  5. "unsafe"
  6. "golang.org/x/sys/windows"
  7. )
  8. var _ unsafe.Pointer
  9. // Do the interface allocations only once for common
  10. // Errno values.
  11. const (
  12. errnoERROR_IO_PENDING = 997
  13. )
  14. var (
  15. errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
  16. errERROR_EINVAL error = syscall.EINVAL
  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 errERROR_EINVAL
  24. case errnoERROR_IO_PENDING:
  25. return errERROR_IO_PENDING
  26. }
  27. // TODO: add more here, after collecting data on the common
  28. // error values see on Windows. (perhaps when running
  29. // all.bat?)
  30. return e
  31. }
  32. var (
  33. modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
  34. procReplaceFileW = modkernel32.NewProc("ReplaceFileW")
  35. )
  36. func replaceFileW(replaced *uint16, replacement *uint16, backup *uint16, flags uint32, exclude unsafe.Pointer, reserved unsafe.Pointer) (err error) {
  37. r1, _, e1 := syscall.SyscallN(procReplaceFileW.Addr(), uintptr(unsafe.Pointer(replaced)), uintptr(unsafe.Pointer(replacement)), uintptr(unsafe.Pointer(backup)), uintptr(flags), uintptr(exclude), uintptr(reserved))
  38. if int32(r1) == 0 {
  39. err = errnoErr(e1)
  40. }
  41. return
  42. }