os_windows.go 964 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2013, Suryandaru Triandana <syndtr@gmail.com>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license.
  5. package main
  6. import (
  7. "syscall"
  8. "unsafe"
  9. )
  10. var (
  11. modkernel32 = syscall.NewLazyDLL("kernel32.dll")
  12. procMoveFileExW = modkernel32.NewProc("MoveFileExW")
  13. )
  14. const _MOVEFILE_REPLACE_EXISTING = 1
  15. func moveFileEx(from *uint16, to *uint16, flags uint32) error {
  16. r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
  17. if r1 == 0 {
  18. if e1 != 0 {
  19. return error(e1)
  20. }
  21. return syscall.EINVAL
  22. }
  23. return nil
  24. }
  25. func rename(oldpath, newpath string) error {
  26. from, err := syscall.UTF16PtrFromString(oldpath)
  27. if err != nil {
  28. return err
  29. }
  30. to, err := syscall.UTF16PtrFromString(newpath)
  31. if err != nil {
  32. return err
  33. }
  34. return moveFileEx(from, to, _MOVEFILE_REPLACE_EXISTING)
  35. }
  36. func syncDir(name string) error { return nil }