12345678910111213141516171819202122 |
- package tick
- import "syscall"
- import "os"
- import "errors"
- func LockFile(file *os.File) error {
- h, err := syscall.LoadLibrary("kernel32.dll")
- if err != nil {
- return err
- }
- defer syscall.FreeLibrary(h)
- addr, err := syscall.GetProcAddress(h, "LockFile")
- if err != nil {
- return err
- }
- r0, _, _ := syscall.Syscall6(addr, 5, file.Fd(), 0, 0, 0, 1, 0)
- if 0 != int(r0) {
- return nil
- }
- return errors.New("resource temporarily unavailable")
- }
|