github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/utils/lockfile/lockfile_windows.go (about) 1 //go:build windows 2 // +build windows 3 4 package lockfile 5 6 import ( 7 "os" 8 "syscall" 9 ) 10 11 func LockFile(file *os.File) error { 12 h, err := syscall.LoadLibrary("kernel32.dll") 13 if err != nil { 14 return err 15 } 16 defer syscall.FreeLibrary(h) 17 18 addr, err := syscall.GetProcAddress(h, "LockFile") 19 if err != nil { 20 return err 21 } 22 23 r0, _, err := syscall.Syscall6(addr, 5, file.Fd(), 0, 0, 0, 1, 0) 24 //fmt.Println(r0, r1, err) 25 if int(r0) != 1 { 26 return err 27 } 28 return nil 29 }