Debian Codegraph @

osfs/os_windows.go

raw symbols SCIP
1 //go:build windows
2 // +build windows
3
4 package osfs
5
6 import (
7 "os"
8 "runtime"
9 "unsafe"
10
11 "golang.org/x/sys/windows"
12 )
13
14 var (
15 kernel32DLL = windows.NewLazySystemDLL("kernel32.dll")
16 lockFileExProc = kernel32DLL.NewProc("LockFileEx")
17 unlockFileProc = kernel32DLL.NewProc("UnlockFile")
18 )
19
20 const (
21 lockfileExclusiveLock = 0x2
22 )
23
24 func (f *file) Lock() error {
25 f.m.Lock()
26 defer f.m.Unlock()
27
28 var overlapped windows.Overlapped
29 // err is always non-nil as per sys/windows semantics.
30 ret, _, err := lockFileExProc.Call(f.File.Fd(), lockfileExclusiveLock, 0, 0xFFFFFFFF, 0,
31 uintptr(unsafe.Pointer(&overlapped)))
32 runtime.KeepAlive(&overlapped)
33 if ret == 0 {
34 return err
35 }
36 return nil
37 }
38
39 func (f *file) Unlock() error {
40 f.m.Lock()
41 defer f.m.Unlock()
42
43 // err is always non-nil as per sys/windows semantics.
44 ret, _, err := unlockFileProc.Call(f.File.Fd(), 0, 0, 0xFFFFFFFF, 0)
45 if ret == 0 {
46 return err
47 }
48 return nil
49 }
50
51 func rename(from, to string) error {
52 return os.Rename(from, to)
53 }
54
55 func umask(new int) func() {
56 return func() {
57 }
58 }