rename_windows.go

2021-09-06 15:12

阅读:770

标签: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


评论


亲,登录后才可以留言!