rename_windows.go
2021-09-06 15:12
标签:span get pre unsafe flags sys oms style top package nsqdimport ( "syscall" "unsafe")var ( modkernel32 = syscall.NewLazyDLL("kernel32.dll") procMoveFileExW = modkernel32.NewProc("MoveFileExW"))const ( MOVEFILE_REPLACE_EXISTING = 1)func moveFileEx(sourceFile, targetFile *uint16, flags uint32) error { ret, _, err := procMoveFileExW.Call(uintptr(unsafe.Pointer(sourceFile)), uintptr(unsafe.Pointer(targetFile)), uintptr(flags)) if ret == 0 { if err != nil { return err } return syscall.EINVAL } return nil}func atomicRename(sourceFile, targetFile string) error { lpReplacedFileName, err := syscall.UTF16PtrFromString(targetFile) if err != nil { return err } lpReplacementFileName, err := syscall.UTF16PtrFromString(sourceFile) if err != nil { return err } return moveFileEx(lpReplacementFileName, lpReplacedFileName, MOVEFILE_REPLACE_EXISTING)}rename_windows.go标签:span get pre unsafe flags sys oms style top 原文地址:http://www.cnblogs.com/zhangboyu/p/7457363.html
文章标题:rename_windows.go
文章链接:http://soscw.com/index.php/essay/107635.html